home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / gnu / djgpp / src / gas-211 / gas / config / tc-m68k.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-05-30  |  114.2 KB  |  5,139 lines

  1. /* tc-m68k.c  All the m68020 specific stuff in one convenient, huge,
  2.    slow to compile, easy to find file.
  3.  
  4.    Copyright (C) 1987, 1991, 1992 Free Software Foundation, Inc.
  5.  
  6.    This file is part of GAS, the GNU Assembler.
  7.  
  8.    GAS is free software; you can redistribute it and/or modify
  9.    it under the terms of the GNU General Public License as published by
  10.    the Free Software Foundation; either version 2, or (at your option)
  11.    any later version.
  12.  
  13.    GAS is distributed in the hope that it will be useful,
  14.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16.    GNU General Public License for more details.
  17.  
  18.    You should have received a copy of the GNU General Public License
  19.    along with GAS; see the file COPYING.  If not, write to
  20.    the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  21.  
  22. #include <ctype.h>
  23. #define  NO_RELOC 0
  24. #include "as.h"
  25.  
  26. /* need TARGET_CPU */
  27. #include "config.h"
  28.  
  29. #include "obstack.h"
  30.  
  31. /* The opcode table is too big for gcc, which (currently) requires
  32.    exponential space at compile time for initialized arrays.  */
  33. #ifdef __GNUC__
  34. #define DO_BREAK_UP_BIG_DECL
  35. #define BREAK_UP_BIG_DECL    }; struct m68k_opcode m68k_opcodes_2[] = {
  36. #define AND_OTHER_PART        sizeof (m68k_opcodes_2)
  37. #endif
  38.  
  39. /* Note that this file includes real declarations and thus can only be
  40.    included by one source file per executable.  */
  41. #include "opcode/m68k.h"
  42.  
  43. #ifndef BFD_ASSEMBLER
  44. #ifdef TE_SUN
  45. /* This variable contains the value to write out at the beginning of
  46.    the a.out file.  The 2<<16 means that this is a 68020 file instead
  47.    of an old-style 68000 file */
  48.  
  49. long omagic = 2 << 16 | OMAGIC;    /* Magic byte for header file */
  50. #else
  51. long omagic = OMAGIC;
  52. #endif
  53. #endif
  54.  
  55. /* This array holds the chars that always start a comment.  If the
  56.    pre-processor is disabled, these aren't very useful */
  57. CONST char comment_chars[] = "|";
  58.  
  59. /* This array holds the chars that only start a comment at the beginning of
  60.    a line.  If the line seems to have the form '# 123 filename'
  61.    .line and .file directives will appear in the pre-processed output */
  62. /* Note that input_file.c hand checks for '#' at the beginning of the
  63.    first line of the input file.  This is because the compiler outputs
  64.    #NO_APP at the beginning of its output. */
  65. /* Also note that comments like this one will always work. */
  66. CONST char line_comment_chars[] = "#";
  67.  
  68. CONST char line_separator_chars[] = "";
  69.  
  70. /* Chars that can be used to separate mant from exp in floating point nums */
  71. CONST char EXP_CHARS[] = "eE";
  72.  
  73. /* Chars that mean this number is a floating point constant, as
  74.    in "0f12.456" or "0d1.2345e12".  */
  75.  
  76. CONST char FLT_CHARS[] = "rRsSfFdDxXeEpP";
  77.  
  78. /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
  79.    changed in read.c .  Ideally it shouldn't have to know about it at all,
  80.    but nothing is ideal around here.  */
  81.  
  82. int md_reloc_size = 8;        /* Size of relocation record */
  83.  
  84. /* Its an arbitrary name:  This means I don't approve of it */
  85. /* See flames below */
  86. static struct obstack robyn;
  87.  
  88. #define TAB(x,y)    (((x)<<2)+(y))
  89. #define TABTYPE(xy)     ((xy) >> 2)
  90. #define BYTE        0
  91. #define SHORT        1
  92. #define LONG        2
  93. #define SZ_UNDEF    3
  94. #undef BRANCH
  95. #define ABRANCH        1
  96. #define FBRANCH        2
  97. #define PCREL        3
  98. #define BCC68000        4
  99. #define DBCC            5
  100. #define PCLEA        6
  101.  
  102. /* Operands we can parse:  (And associated modes)
  103.  
  104.    numb:    8 bit num
  105.    numw:    16 bit num
  106.    numl:    32 bit num
  107.    dreg:    data reg 0-7
  108.    reg:    address or data register
  109.    areg:    address register
  110.    apc:    address register, PC, ZPC or empty string
  111.    num:    16 or 32 bit num
  112.    num2:    like num
  113.    sz:    w or l        if omitted, l assumed
  114.    scale:    1 2 4 or 8    if omitted, 1 assumed
  115.  
  116.    7.4 IMMED #num                --> NUM
  117.    0.? DREG  dreg                --> dreg
  118.    1.? AREG  areg                --> areg
  119.    2.? AINDR areg@                --> *(areg)
  120.    3.? AINC  areg@+            --> *(areg++)
  121.    4.? ADEC  areg@-            --> *(--areg)
  122.    5.? AOFF  apc@(numw)            --> *(apc+numw)    -- empty string and ZPC not allowed here
  123.    6.? AINDX apc@(num,reg:sz:scale)    --> *(apc+num+reg*scale)
  124.    6.? AINDX apc@(reg:sz:scale)        --> same, with num=0
  125.    6.? APODX apc@(num)@(num2,reg:sz:scale)    --> *(*(apc+num)+num2+reg*scale)
  126.    6.? APODX apc@(num)@(reg:sz:scale)    --> same, with num2=0
  127.    6.? AMIND apc@(num)@(num2)        --> *(*(apc+num)+num2) (previous mode without an index reg)
  128.    6.? APRDX apc@(num,reg:sz:scale)@(num2)    --> *(*(apc+num+reg*scale)+num2)
  129.    6.? APRDX apc@(reg:sz:scale)@(num2)    --> same, with num=0
  130.    7.0 ABSL  num:sz            --> *(num)
  131.    num                --> *(num) (sz L assumed)
  132.    *** MSCR  otherreg            --> Magic
  133.    With -l option
  134.    5.? AOFF  apc@(num)            --> *(apc+num) -- empty string and ZPC not allowed here still
  135.    ?.? DINDR dreg@            --> (dreg) -- cas2 only
  136.  
  137.    examples:
  138.    #foo    #0x35    #12
  139.    d2
  140.    a4
  141.    a3@
  142.    a5@+
  143.    a6@-
  144.    a2@(12)    pc@(14)
  145.    a1@(5,d2:w:1)    @(45,d6:l:4)
  146.    pc@(a2)        @(d4)
  147.    etc . . .
  148.  
  149.  
  150.    #name@(numw)    -->turn into PC rel mode
  151.    apc@(num8,reg:sz:scale)        --> *(apc+num8+reg*scale)
  152.  
  153.    */
  154.  
  155. enum operand_type
  156.   {
  157.     IMMED = 1,
  158.     DREG,
  159.     AREG,
  160.     AINDR,
  161.     ADEC,
  162.     AINC,
  163.     AOFF,
  164.     AINDX,
  165.     APODX,
  166.     AMIND,
  167.     APRDX,
  168.     ABSL,
  169.     MSCR,
  170.     REGLST,
  171.     DINDR
  172.   };
  173.  
  174.  
  175. struct m68k_exp
  176.   {
  177.     char *e_beg;
  178.     char *e_end;
  179.     expressionS e_exp;
  180.     short e_siz;        /* 0== default 1==short/byte 2==word 3==long */
  181.   };
  182.  
  183. /* DATA and ADDR have to be contiguous, so that reg-DATA gives 0-7==data reg,
  184.    8-15==addr reg for operands that take both types */
  185.  
  186. enum _register
  187.   {
  188.     DATA = 1,            /*   1- 8 == data registers 0-7 */
  189.     DATA0 = DATA,
  190.     DATA1,
  191.     DATA2,
  192.     DATA3,
  193.     DATA4,
  194.     DATA5,
  195.     DATA6,
  196.     DATA7,
  197.  
  198.     ADDR,
  199.     ADDR0 = ADDR,
  200.     ADDR1,
  201.     ADDR2,
  202.     ADDR3,
  203.     ADDR4,
  204.     ADDR5,
  205.     ADDR6,
  206.     ADDR7,
  207.  
  208.     /* Note that COPNUM==processor #1 -- COPNUM+7==#8, which stores as 000 */
  209.     /* I think. . .  */
  210.  
  211.     SP = ADDR7,
  212.  
  213.     FPREG,            /* Eight FP registers */
  214.     FP0 = FPREG,
  215.     FP1,
  216.     FP2,
  217.     FP3,
  218.     FP4,
  219.     FP5,
  220.     FP6,
  221.     FP7,
  222.     COPNUM = (FPREG + 8),    /* Co-processor #1-#8 */
  223.     COP0 = COPNUM,
  224.     COP1,
  225.     COP2,
  226.     COP3,
  227.     COP4,
  228.     COP5,
  229.     COP6,
  230.     COP7,
  231.     PC,                /* Program counter */
  232.     ZPC,            /* Hack for Program space, but 0 addressing */
  233.     SR,                /* Status Reg */
  234.     CCR,            /* Condition code Reg */
  235.  
  236.     /* These have to be in order for the movec instruction to work. */
  237.     USP,            /*  User Stack Pointer */
  238.     ISP,            /*  Interrupt stack pointer */
  239.     SFC,
  240.     DFC,
  241.     CACR,
  242.     VBR,
  243.     CAAR,
  244.     MSP,
  245.     ITT0,
  246.     ITT1,
  247.     DTT0,
  248.     DTT1,
  249.     MMUSR,
  250.     TC,
  251.     SRP,
  252.     URP,
  253.     /* end of movec ordering constraints */
  254.  
  255.     FPI,
  256.     FPS,
  257.     FPC,
  258.  
  259.     DRP,            /* 68851 or 68030 MMU regs */
  260.     CRP,
  261.     CAL,
  262.     VAL,
  263.     SCC,
  264.     AC,
  265.     BAD,
  266.     BAD0 = BAD,
  267.     BAD1,
  268.     BAD2,
  269.     BAD3,
  270.     BAD4,
  271.     BAD5,
  272.     BAD6,
  273.     BAD7,
  274.     BAC,
  275.     BAC0 = BAC,
  276.     BAC1,
  277.     BAC2,
  278.     BAC3,
  279.     BAC4,
  280.     BAC5,
  281.     BAC6,
  282.     BAC7,
  283.     PSR,            /* aka MMUSR on 68030 (but not MMUSR on 68040)
  284.                    and ACUSR on 68ec030 */
  285.     PCSR,
  286.  
  287.     IC,                /* instruction cache token */
  288.     DC,                /* data cache token */
  289.     NC,                /* no cache token */
  290.     BC,                /* both caches token */
  291.  
  292.     TT0,            /* 68030 access control unit regs */
  293.     TT1,
  294.   };
  295.  
  296. /* Internal form of an operand.  */
  297. struct m68k_op
  298.   {
  299.     char *error;        /* Couldn't parse it */
  300.     enum operand_type mode;    /* What mode this instruction is in.  */
  301.     enum _register reg;        /* Base register */
  302.     struct m68k_exp *con1;
  303.     int ireg;            /* Index register */
  304.     int isiz;            /* 0==unspec  1==byte(?)  2==short  3==long  */
  305.     int imul;            /* Multipy ireg by this (1,2,4,or 8) */
  306.     struct m68k_exp *con2;
  307.   };
  308.  
  309. /* internal form of a 68020 instruction */
  310. struct m68k_it
  311.   {
  312.     char *error;
  313.     char *args;            /* list of opcode info */
  314.     int numargs;
  315.  
  316.     int numo;            /* Number of shorts in opcode */
  317.     short opcode[11];
  318.  
  319.     struct m68k_op operands[6];
  320.  
  321.     int nexp;            /* number of exprs in use */
  322.     struct m68k_exp exprs[4];
  323.  
  324.     int nfrag;            /* Number of frags we have to produce */
  325.     struct
  326.       {
  327.     int fragoff;        /* Where in the current opcode[] the frag ends */
  328.     symbolS *fadd;
  329.     long foff;
  330.     int fragty;
  331.       }
  332.     fragb[4];
  333.  
  334.     int nrel;            /* Num of reloc strucs in use */
  335.     struct
  336.       {
  337.     int n;
  338.     symbolS *add, *sub;
  339.     long off;
  340.     char wid;
  341.     char pcrel;
  342.       }
  343.     reloc[5];            /* Five is enough??? */
  344.   };
  345.  
  346. #define cpu_of_arch(x)        ((x) & m68000up)
  347. #define float_of_arch(x)    ((x) & mfloat)
  348. #define mmu_of_arch(x)        ((x) & mmmu)
  349.  
  350. static struct m68k_it the_ins;    /* the instruction being assembled */
  351.  
  352. #define seg(exp)    ((exp)->e_exp.X_seg)
  353. #define adds(exp)    ((exp)->e_exp.X_add_symbol)
  354. #define subs(exp)    ((exp)->e_exp.X_subtract_symbol)
  355. #define offs(exp)    ((exp)->e_exp.X_add_number)
  356.  
  357. /* Macros for adding things to the m68k_it struct */
  358.  
  359. #define addword(w)    the_ins.opcode[the_ins.numo++]=(w)
  360.  
  361. /* Like addword, but goes BEFORE general operands */
  362. #define insop(w)    {int z;\
  363.                  for(z=the_ins.numo;z>opcode->m_codenum;--z)\
  364.                  the_ins.opcode[z]=the_ins.opcode[z-1];\
  365.                      for(z=0;z<the_ins.nrel;z++)\
  366.                      the_ins.reloc[z].n+=2;\
  367.                          the_ins.opcode[opcode->m_codenum]=w;\
  368.                          the_ins.numo++;\
  369.                          }
  370.  
  371.  
  372. #define add_exp(beg,end) (\
  373.               the_ins.exprs[the_ins.nexp].e_beg=beg,\
  374.               the_ins.exprs[the_ins.nexp].e_end=end,\
  375.               &the_ins.exprs[the_ins.nexp++]\
  376.               )
  377.  
  378.  
  379. /* The numo+1 kludge is so we can hit the low order byte of the prev word.
  380.    Blecch.  */
  381. static void
  382. add_fix (width, exp, pc_rel)
  383.      char width;
  384.      struct m68k_exp *exp;
  385.      int pc_rel;
  386. {
  387.   the_ins.reloc[the_ins.nrel].n = (((width)=='B')
  388.                    ? (the_ins.numo*2-1)
  389.                    : (((width)=='b')
  390.                       ? ((the_ins.numo-1)*2)
  391.                       : (the_ins.numo*2)));
  392.   the_ins.reloc[the_ins.nrel].add = adds((exp));
  393.   the_ins.reloc[the_ins.nrel].sub = subs((exp));
  394.   the_ins.reloc[the_ins.nrel].off = offs((exp));
  395.   the_ins.reloc[the_ins.nrel].wid = width;
  396.   the_ins.reloc[the_ins.nrel++].pcrel = pc_rel;
  397. }
  398.  
  399. static void
  400. add_frag(add,off,type)
  401.      symbolS *add;
  402.      long off;
  403.      int type;
  404. {
  405.   the_ins.fragb[the_ins.nfrag].fragoff=the_ins.numo;
  406.   the_ins.fragb[the_ins.nfrag].fadd=add;
  407.   the_ins.fragb[the_ins.nfrag].foff=off;
  408.   the_ins.fragb[the_ins.nfrag++].fragty=type;
  409. }
  410.  
  411. #define isvar(exp)    ((exp) && (adds(exp) || subs(exp)))
  412.  
  413. struct m68k_incant
  414.   {
  415.     char *m_operands;
  416.     unsigned long m_opcode;
  417.     short m_opnum;
  418.     short m_codenum;
  419.     int m_arch;
  420.     struct m68k_incant *m_next;
  421.   };
  422.  
  423.  
  424.  
  425. #define getone(x)    ((((x)->m_opcode)>>16)&0xffff)
  426. #define gettwo(x)    (((x)->m_opcode)&0xffff)
  427.  
  428.  
  429. static char *crack_operand PARAMS ((char *str, struct m68k_op *opP));
  430. static int get_num PARAMS ((struct m68k_exp *exp, int ok));
  431. static int get_regs PARAMS ((int i, char *str, struct m68k_op *opP));
  432. static int reverse_16_bits PARAMS ((int in));
  433. static int reverse_8_bits PARAMS ((int in));
  434. static int try_index PARAMS ((char **s, struct m68k_op *opP));
  435. static void install_gen_operand PARAMS ((int mode, int val));
  436. static void install_operand PARAMS ((int mode, int val));
  437. static void s_bss PARAMS ((void));
  438. static void s_data1 PARAMS ((void));
  439. static void s_data2 PARAMS ((void));
  440. static void s_even PARAMS ((void));
  441. static void s_proc PARAMS ((void));
  442.  
  443. static int current_architecture;
  444.  
  445. /* BCC68000 is for patching in an extra jmp instruction for long offsets
  446.    on the 68000.  The 68000 doesn't support long branches with branchs */
  447.  
  448. /* This table desribes how you change sizes for the various types of variable
  449.    size expressions.  This version only supports two kinds. */
  450.  
  451. /* Note that calls to frag_var need to specify the maximum expansion needed */
  452. /* This is currently 10 bytes for DBCC */
  453.  
  454. /* The fields are:
  455.    How far Forward this mode will reach:
  456.    How far Backward this mode will reach:
  457.    How many bytes this mode will add to the size of the frag
  458.    Which mode to go to if the offset won't fit in this one
  459.    */
  460. CONST relax_typeS md_relax_table[] =
  461. {
  462.   {1, 1, 0, 0},            /* First entries aren't used */
  463.   {1, 1, 0, 0},            /* For no good reason except */
  464.   {1, 1, 0, 0},            /* that the VAX doesn't either */
  465.   {1, 1, 0, 0},
  466.  
  467.   {(127), (-128), 0, TAB (ABRANCH, SHORT)},
  468.   {(32767), (-32768), 2, TAB (ABRANCH, LONG)},
  469.   {0, 0, 4, 0},
  470.   {1, 1, 0, 0},
  471.  
  472.   {1, 1, 0, 0},            /* FBRANCH doesn't come BYTE */
  473.   {(32767), (-32768), 2, TAB (FBRANCH, LONG)},
  474.   {0, 0, 4, 0},
  475.   {1, 1, 0, 0},
  476.  
  477.   {1, 1, 0, 0},            /* PCREL doesn't come BYTE */
  478.   {(32767), (-32768), 2, TAB (PCREL, LONG)},
  479.   {0, 0, 4, 0},
  480.   {1, 1, 0, 0},
  481.  
  482.   {(127), (-128), 0, TAB (BCC68000, SHORT)},
  483.   {(32767), (-32768), 2, TAB (BCC68000, LONG)},
  484.   {0, 0, 6, 0},            /* jmp long space */
  485.   {1, 1, 0, 0},
  486.  
  487.   {1, 1, 0, 0},            /* DBCC doesn't come BYTE */
  488.   {(32767), (-32768), 2, TAB (DBCC, LONG)},
  489.   {0, 0, 10, 0},        /* bra/jmp long space */
  490.   {1, 1, 0, 0},
  491.  
  492.   {1, 1, 0, 0},            /* PCLEA doesn't come BYTE */
  493.   {32767, -32768, 2, TAB (PCLEA, LONG)},
  494.   {0, 0, 6, 0},
  495.   {1, 1, 0, 0},
  496.  
  497. };
  498.  
  499. /* These are the machine dependent pseudo-ops.  These are included so
  500.    the assembler can work on the output from the SUN C compiler, which
  501.    generates these.
  502.    */
  503.  
  504. /* This table describes all the machine specific pseudo-ops the assembler
  505.    has to support.  The fields are:
  506.    pseudo-op name without dot
  507.    function to call to execute this pseudo-op
  508.    Integer arg to pass to the function
  509.    */
  510. CONST pseudo_typeS md_pseudo_table[] =
  511. {
  512.   {"data1", s_data1, 0},
  513.   {"data2", s_data2, 0},
  514.   {"bss", s_bss, 0},
  515.   {"even", s_even, 0},
  516.   {"skip", s_space, 0},
  517.   {"proc", s_proc, 0},
  518. #ifdef TE_SUN3
  519.   {"align", s_align_bytes, 0},
  520. #endif
  521.   {0, 0, 0}
  522. };
  523.  
  524.  
  525. /* The mote pseudo ops are put into the opcode table, since they
  526.    don't start with a . they look like opcodes to gas.
  527.    */
  528. extern void obj_coff_section ();
  529.  
  530. CONST pseudo_typeS mote_pseudo_table[] =
  531. {
  532.  
  533.   {"dc.l", cons, 4},
  534.   {"dc", cons, 2},
  535.   {"dc.w", cons, 2},
  536.   {"dc.b", cons, 1},
  537.  
  538.   {"ds.l", s_space, 4},
  539.   {"ds", s_space, 2},
  540.   {"ds.w", s_space, 2},
  541.   {"ds.b", s_space, 1},
  542.  
  543.   {"xdef", s_globl, 0},
  544.   {"align", s_align_ptwo, 0},
  545. #ifdef M68KCOFF
  546.   {"sect", obj_coff_section, 0},
  547.   {"section", obj_coff_section, 0},
  548. #endif
  549.   0,
  550. };
  551.  
  552. /* #define isbyte(x)    ((x)>=-128 && (x)<=127) */
  553. /* #define isword(x)    ((x)>=-32768 && (x)<=32767) */
  554.  
  555. #define issbyte(x)    ((x)>=-128 && (x)<=127)
  556. #define isubyte(x)    ((x)>=0 && (x)<=255)
  557. #define issword(x)    ((x)>=-32768 && (x)<=32767)
  558. #define isuword(x)    ((x)>=0 && (x)<=65535)
  559.  
  560. #define isbyte(x)    ((x)>= -255 && (x)<=255)
  561. #define isword(x)    ((x)>=-32768 && (x)<=65535)
  562. #define islong(x)    (1)
  563.  
  564. extern char *input_line_pointer;
  565.  
  566. enum
  567.   {
  568.     FAIL = 0,
  569.     OK = 1,
  570.   };
  571.  
  572. /* JF these tables here are for speed at the expense of size */
  573. /* You can replace them with the #if 0 versions if you really
  574.    need space and don't mind it running a bit slower */
  575.  
  576. static char mklower_table[256];
  577. #define mklower(c) (mklower_table[(unsigned char)(c)])
  578. static char notend_table[256];
  579. static char alt_notend_table[256];
  580. #define notend(s) ( !(notend_table[(unsigned char)(*s)] || (*s==':' &&\
  581.                                 alt_notend_table[(unsigned char)(s[1])])))
  582.  
  583. #if 0
  584. #define mklower(c)    (isupper(c) ? tolower(c) : c)
  585. #endif
  586.  
  587.  
  588. /* JF modified this to handle cases where the first part of a symbol name
  589.    looks like a register */
  590.  
  591. /*
  592.  * m68k_reg_parse() := if it looks like a register, return it's token &
  593.  * advance the pointer.
  594.  */
  595.  
  596. enum _register
  597. m68k_reg_parse (ccp)
  598.      register char **ccp;
  599. {
  600.   char *start = *ccp;
  601.   char c;
  602.   char *p;
  603.   symbolS *symbolP;
  604.  
  605. #ifdef REGISTER_PREFIX
  606.   if (*start != REGISTER_PREFIX)
  607.     return FAIL;
  608.   p = start + 1;
  609. #else
  610.   p = start;
  611.   if (*p == OPTIONAL_REGISTER_PREFIX)
  612.     p++, start++;
  613. #endif
  614.   if (!isalpha (*p) || !is_name_beginner (*p))
  615.     return FAIL;
  616.  
  617.   c = *p++;
  618.   while (isalpha (c) || isdigit (c) || c == '_')
  619.     {
  620.       c = *p++;
  621.     }
  622.  
  623.   *--p = 0;
  624.   symbolP = symbol_find (start);
  625.   *p = c;
  626.  
  627.   if (symbolP && S_GET_SEGMENT (symbolP) == reg_section)
  628.     {
  629.       *ccp = p;
  630.       return S_GET_VALUE (symbolP);
  631.     }
  632.  
  633.   return FAIL;
  634. }
  635.  
  636. #define SKIP_WHITE()    { str++; if(*str==' ') str++;}
  637. #define SKIP_W()    { ss++; if(*ss==' ') ss++;}
  638.  
  639. /* Parse an index specification using Motorola syntax.  */
  640.  
  641. static int
  642. try_moto_index (s, opP)
  643.      char **s;
  644.      struct m68k_op *opP;
  645. {
  646.   register int i;
  647.   char *ss;
  648.  
  649.   ss = *s;
  650.   /* SKIP_W(); */
  651.   if (*ss == ' ')
  652.     ss++;
  653.   i = m68k_reg_parse (&ss);
  654.   if (!(i >= DATA + 0 && i <= ADDR + 7))
  655.     {                /* if i is not DATA or ADDR reg */
  656.       opP->error = "Invalid index register";
  657.       *s = ss;
  658.       return FAIL;
  659.     }
  660.   opP->ireg = i;
  661.   /* SKIP_W(); */
  662.   if (*ss == ')')
  663.     {
  664.       opP->isiz = 0;
  665.       opP->imul = 1;
  666.       SKIP_W ();
  667.       *s = ss;
  668.       return OK;
  669.     }
  670.   if (*ss != '.')
  671.     {
  672.       opP->error = "Missing . in index register";
  673.       *s = ss;
  674.       return FAIL;
  675.     }
  676.   SKIP_W ();
  677.   if (mklower (*ss) == 'w')
  678.     opP->isiz = 2;
  679.   else if (mklower (*ss) == 'l')
  680.     opP->isiz = 3;
  681.   else
  682.     {
  683.       opP->error = "Size spec not .W or .L";
  684.       *s = ss;
  685.       return FAIL;
  686.     }
  687.   SKIP_W ();
  688.   if (*ss == '.' || *ss == '*')
  689.     {
  690.       SKIP_W ();
  691.       switch (*ss)
  692.     {
  693.     case '1':
  694.     case '2':
  695.     case '4':
  696.     case '8':
  697.       opP->imul = *ss - '0';
  698.       break;
  699.     default:
  700.       opP->error = "index multiplier not 1, 2, 4 or 8";
  701.       *s = ss;
  702.       return FAIL;
  703.     }
  704.       SKIP_W ();
  705.     }
  706.   else
  707.     opP->imul = 1;
  708.   if (*ss != ')')
  709.     {
  710.       opP->error = "Missing )";
  711.       *s = ss;
  712.       return FAIL;
  713.     }
  714.   SKIP_W ();
  715.   *s = ss;
  716.   return OK;
  717. }
  718.  
  719. /*
  720.  *
  721.  * try_index := data_or_address_register + ')' + SKIP_W
  722.  *    | data_or_address_register + ':' + SKIP_W + size_spec + SKIP_W + multiplier + ')' + SKIP_W
  723.  *
  724.  * multiplier := <empty>
  725.  *    | ':' + multiplier_number
  726.  *    ;
  727.  *
  728.  * multiplier_number := '1' | '2' | '4' | '8' ;
  729.  *
  730.  * size_spec := 'l' | 'L' | 'w' | 'W' ;
  731.  *
  732.  * SKIP_W := <empty> | ' ' ;
  733.  *
  734.  */
  735.  
  736. static int
  737. try_index (s, opP)
  738.      char **s;
  739.      struct m68k_op *opP;
  740. {
  741.   register int i;
  742.   char *ss;
  743.  
  744.   ss = *s;
  745.   /* SKIP_W(); */
  746.   i = m68k_reg_parse (&ss);
  747.   if (!(i >= DATA + 0 && i <= ADDR + 7))
  748.     {                /* if i is not DATA or ADDR reg */
  749.       *s = ss;
  750.       return FAIL;
  751.     }
  752.   opP->ireg = i;
  753.   /* SKIP_W(); */
  754.   if (*ss == ')')
  755.     {
  756.       opP->isiz = 0;
  757.       opP->imul = 1;
  758.       SKIP_W ();
  759.       *s = ss;
  760.       return OK;
  761.     }
  762.   if (*ss != ':')
  763.     {
  764.       opP->error = "Missing : in index register";
  765.       *s = ss;
  766.       return FAIL;
  767.     }
  768.   SKIP_W ();
  769.   switch (*ss)
  770.     {
  771.     case 'w':
  772.     case 'W':
  773.       opP->isiz = 2;
  774.       break;
  775.     case 'l':
  776.     case 'L':
  777.       opP->isiz = 3;
  778.       break;
  779.     default:
  780.       opP->error = "Index register size spec not :w or :l";
  781.       *s = ss;
  782.       return FAIL;
  783.     }
  784.   SKIP_W ();
  785.   if (*ss == ':')
  786.     {
  787.       SKIP_W ();
  788.       switch (*ss)
  789.     {
  790.     case '1':
  791.     case '2':
  792.     case '4':
  793.     case '8':
  794.       if (cpu_of_arch (current_architecture) < m68020)
  795.         {
  796.           opP->error = "no index scaling in pre-68020's";
  797.           *s = ss;
  798.           return FAIL;
  799.         }
  800.       opP->imul = *ss - '0';
  801.       break;
  802.     default:
  803.       opP->error = "index multiplier not 1, 2, 4 or 8";
  804.       *s = ss;
  805.       return FAIL;
  806.     }
  807.       SKIP_W ();
  808.     }
  809.   else
  810.     opP->imul = 1;
  811.   if (*ss != ')')
  812.     {
  813.       opP->error = "Missing )";
  814.       *s = ss;
  815.       return FAIL;
  816.     }
  817.   SKIP_W ();
  818.   *s = ss;
  819.   return OK;
  820. }                /* try_index() */
  821.  
  822. /* Ian Taylor expanded this function to accept both MIT and Motorola
  823.    syntax.  I removed the old comment, since it was wrong.  The syntax
  824.    this accepted even before my changes was complex and undocumented.
  825.    I mainly added a large case when the operand string does not
  826.    contain an '@', since the Motorola syntax does not use the '@'
  827.    character.  */
  828.  
  829. int
  830. m68k_ip_op (str, opP)
  831.      char *str;
  832.      register struct m68k_op *opP;
  833. {
  834.   char *strend;
  835.   long i;
  836.   char *parse_index ();
  837.   int needp;
  838.  
  839.   if (*str == ' ')
  840.     {
  841.       str++;
  842.     }                /* Find the beginning of the string */
  843.  
  844.   if (!*str)
  845.     {
  846.       opP->error = "Missing operand";
  847.       return FAIL;
  848.     }                /* Out of gas */
  849.  
  850.   for (strend = str; *strend; strend++)
  851.     ;
  852.   --strend;
  853.  
  854.   if (*str == '#')
  855.     {
  856.       str++;
  857.       opP->con1 = add_exp (str, strend);
  858.       opP->mode = IMMED;
  859.       return OK;
  860.     }                /* Guess what:  A constant.  Shar and enjoy */
  861.  
  862.   i = m68k_reg_parse (&str);
  863.  
  864.   if (i != FAIL)
  865.     {
  866.       if (*str == '/' || *str == '-')
  867.     {
  868.       /* "Rm-Rn/Ro-Rp"  Register list for MOVEM instruction */
  869.       opP->mode = REGLST;
  870.       return get_regs (i, str, opP);
  871.     }
  872.       if (*str == '\0')
  873.     {
  874.       opP->reg = i;
  875.       /* "Rn"  Register Direct mode */
  876.       if (i >= DATA + 0 && i <= DATA + 7)
  877.         opP->mode = DREG;
  878.       else if (i >= ADDR + 0 && i <= ADDR + 7)
  879.         opP->mode = AREG;
  880.       else
  881.         opP->mode = MSCR;
  882.       return OK;
  883.     }
  884.     }
  885.  
  886.   if (*str != '@')
  887.     {
  888.       char *stmp;
  889.  
  890.       if ((stmp = strchr (str, '@')) != 0)
  891.     {
  892.       opP->con1 = add_exp (str, stmp - 1);
  893.       if (stmp == strend)
  894.         {
  895.           opP->mode = AINDX;
  896.           return (OK);
  897.         }
  898.  
  899.       if ((current_architecture & m68020up) == 0)
  900.         {
  901.           return (FAIL);
  902.         }            /* if target is not a '20 or better */
  903.  
  904.       stmp++;
  905.       if (*stmp++ != '(' || *strend-- != ')')
  906.         {
  907.           opP->error = "Malformed operand";
  908.           return (FAIL);
  909.         }
  910.       i = try_index (&stmp, opP);
  911.       opP->con2 = add_exp (stmp, strend);
  912.  
  913.       if (i == FAIL)
  914.         {
  915.           opP->mode = AMIND;
  916.         }
  917.       else
  918.         {
  919.           opP->mode = APODX;
  920.         }
  921.       return (OK);
  922.     }            /* if there's an '@' */
  923.  
  924. #ifndef MIT_SYNTAX_ONLY
  925.       /* The operand has no '@'.  Try to parse it using
  926.      Motorola syntax.  */
  927.       /* Logic of the parsing switch(*str):
  928.            case            opP->mode =
  929.            ----            -----------
  930.            #anything        IMMED    1
  931.            REG                AREG or DREG or MSCR    3 or 2 or 13
  932.            REG- or REG/            REGLST    14
  933.            (REG)        AINDR    4
  934.            (REG)+            AINC       6
  935.            (REG,INDX)            AINDX    8
  936.            (EXPR,REG)            AOFF       7
  937.            (EXPR,REG,INDX)      AINDX    8
  938.            -(REG)              ADEC       5
  939.            EXP2(REG)        AOFF       7
  940.            EXP2(REG,INDX)    AINDX    8
  941.            EXP2            ABSL       12
  942.  
  943.            REG  means truth(m68k_reg_parse(&str))
  944.            INDX means truth(try_moto_index(&str,opP))
  945.            EXPR means not REG
  946.            EXP2 means not REG and not '(' and not '-('
  947.            */
  948.  
  949.       if (*str == '(')
  950.     {
  951.       str++;
  952.       i = m68k_reg_parse (&str);
  953.       if ((i < ADDR + 0 || i > ADDR + 7)
  954.           && (i < DATA + 0 || i > DATA + 7
  955.           || *str != ')' || str[1] != '0')
  956.           && i != PC && i != ZPC && i != FAIL)
  957.         {
  958.           /* Can't indirect off non address regs */
  959.           opP->error = "Invalid indirect register";
  960.           return FAIL;
  961.         }
  962.       if (i != FAIL)
  963.         {
  964.           opP->reg = i;
  965.           if (*str == ')')
  966.         {
  967.           str++;
  968.           if (*str == '\0')
  969.             {
  970.               /* "(An)"  Address Register Indirect mode
  971.                      or "(Dn)" for cas2.  */
  972.               if (i >= DATA + 0 && i <= DATA + 7)
  973.             opP->mode = DINDR;
  974.               else
  975.             opP->mode = AINDR;
  976.               return OK;
  977.             }
  978.           if (*str == '+')
  979.             {
  980.               if (str[1] == '\0')
  981.             {
  982.               /* "(An)+" Register Indirect w Postincrement */
  983.               opP->mode = AINC;
  984.               return OK;
  985.             }
  986.             }
  987.           opP->error = "Junk after indirect";
  988.           return FAIL;
  989.         }
  990.           if (*str == ',')
  991.         {
  992.           str++;
  993.           i = try_moto_index (&str, opP);
  994.           if (i == FAIL)
  995.             return FAIL;
  996.           /* "(An,Rn)"  Register Indirect with Index mode*/
  997.           opP->mode = AINDX;
  998.           return OK;
  999.         }
  1000.           else
  1001.         {
  1002.           opP->error = "Bad indirect syntax";
  1003.           return FAIL;
  1004.         }
  1005.         }
  1006.       else
  1007.         {
  1008.           /* "(EXPR,..." , a displacement */
  1009.           char *stmp;
  1010.           char *index ();
  1011.  
  1012.           if (stmp = index (str, ','))
  1013.         {
  1014.           opP->con1 = add_exp (str, stmp - 1);
  1015.           str = stmp;
  1016.           SKIP_WHITE ();
  1017.           i = m68k_reg_parse (&str);
  1018.           if ((i < ADDR + 0 || i > ADDR + 7) && i != PC && i != ZPC)
  1019.             {
  1020.               /* Can't indirect off non address regs */
  1021.               opP->error = "Invalid indirect register";
  1022.               return FAIL;
  1023.             }
  1024.           if (i != FAIL)
  1025.             {
  1026.               opP->reg = i;
  1027.               if (*str == ')')
  1028.             {
  1029.               /* "(d,An)"  Register Indirect w Displacement */
  1030.               opP->mode = AOFF;
  1031.               return OK;
  1032.             }
  1033.               if (*str == ',')
  1034.             {
  1035.               str++;
  1036.               i = try_moto_index (&str, opP);
  1037.               if (i == FAIL)
  1038.                 return FAIL;
  1039.               /* "(d,An,Rn)"  Register Indirect with Index */
  1040.               opP->mode = AINDX;
  1041.               return OK;
  1042.             }
  1043.               else
  1044.             {
  1045.               opP->error = "Bad indirect syntax";
  1046.               return FAIL;
  1047.             }
  1048.             }
  1049.           else
  1050.             {
  1051.               opP->error = "Invalid register";
  1052.               return FAIL;
  1053.             }
  1054.         }
  1055.           else
  1056.         {
  1057.           opP->mode = ABSL;
  1058.           opP->con1 = add_exp (str - 1, strend);
  1059.           return OK;
  1060.         }
  1061.         }
  1062.     }
  1063.  
  1064.       if (*str == '-')
  1065.     {
  1066.       if (str[1] == '(')
  1067.         {
  1068.           str = str + 2;
  1069.           i = m68k_reg_parse (&str);
  1070.           if ((i < ADDR + 0 || i > ADDR + 7) && i != PC && i != ZPC && i != FAIL)
  1071.         {
  1072.           /* Can't indirect off non address regs */
  1073.           opP->error = "Invalid indirect register";
  1074.           return FAIL;
  1075.         }
  1076.           if (i != FAIL)
  1077.         {
  1078.           opP->reg = i;
  1079.           if (*str == ')')
  1080.             {
  1081.               str++;
  1082.               if (*str == '\0')
  1083.             {
  1084.               /* "-(An)" Register Indirect with Predecrement */
  1085.               opP->mode = ADEC;
  1086.               return OK;
  1087.             }
  1088.               opP->error = "Junk after indirect";
  1089.               return FAIL;
  1090.             }
  1091.           opP->error = "Bad indirect syntax";
  1092.           return FAIL;
  1093.         }
  1094.           opP->mode = ABSL;
  1095.           opP->con1 = add_exp (str - 2, strend);
  1096.           return OK;
  1097.         }
  1098.       /* if '-' but not "-(', do nothing */
  1099.     }
  1100.  
  1101.       /* whether *str=='-' or not */
  1102.       {
  1103.     /* "EXP2" or "EXP2(REG..." */
  1104.     char *stmp;
  1105.     char *index ();
  1106.     if (stmp = index (str, '('))
  1107.       {
  1108.         char *ostr = str;
  1109.  
  1110.         opP->con1 = add_exp (str, stmp - 1);
  1111.         str = stmp + 1;
  1112.         i = m68k_reg_parse (&str);
  1113.         if ((i < ADDR + 0 || i > ADDR + 7) && i != PC
  1114.         && i != ZPC && i != FAIL)
  1115.           {
  1116.         /* Can't indirect off non address regs */
  1117.         opP->error = "Invalid indirect register";
  1118.         return FAIL;
  1119.           }
  1120.         if (i != FAIL)
  1121.           {
  1122.         opP->reg = i;
  1123.         if (*str == ')')
  1124.           {
  1125.             /* "d(An)"  Register Indirect w Displacement */
  1126.             opP->mode = AOFF;
  1127.             return OK;
  1128.           }
  1129.         if (*str == ',')
  1130.           {
  1131.             str++;
  1132.             i = try_moto_index (&str, opP);
  1133.             if (i == FAIL)
  1134.               return FAIL;
  1135.             /* "d(An,Rn)"  Register Indirect with Index */
  1136.             opP->mode = AINDX;
  1137.             return OK;
  1138.           }
  1139.         else
  1140.           {
  1141.             opP->error = "Bad indirect syntax";
  1142.             return FAIL;
  1143.           }
  1144.           }
  1145.         else
  1146.           {
  1147.         opP->mode = ABSL;
  1148.         opP->con1 = add_exp (ostr, strend);
  1149.         return OK;
  1150.           }
  1151.       }
  1152.     else
  1153.       {
  1154.         /* "EXP2"  Absolute */
  1155.         opP->mode = ABSL;
  1156.         opP->isiz = 0;
  1157.         if (strend[-1] == '.' || strend[-1] == ':')
  1158.           {
  1159.         /* mode ==foo.[wl] */
  1160.         switch (*strend)
  1161.           {
  1162.           case 'w':
  1163.           case 'W':
  1164.             opP->isiz = 2;
  1165.             strend -= 2;
  1166.             break;
  1167.           case 'l':
  1168.           case 'L':
  1169.             opP->isiz = 3;
  1170.             strend -= 2;
  1171.             break;
  1172.           }
  1173.           }
  1174.         opP->con1 = add_exp (str, strend);
  1175.         return OK;
  1176.       }
  1177.       }
  1178.       /*NOTREACHED*/
  1179. #else /* defined (MIT_SYNTAX_ONLY) */
  1180.       opP->mode = ABSL;
  1181.       opP->con1 = add_exp (str, strend);
  1182.       return OK;
  1183. #endif /* defined (MIT_SYNTAX_ONLY) */
  1184.     }
  1185.  
  1186.   opP->reg = i;
  1187.  
  1188.   /* Can't indirect off non address regs, but Dx@ is OK for cas2 */
  1189.   if ((i < ADDR + 0 || i > ADDR + 7) && i != PC && i != ZPC && i != FAIL
  1190.       && (str[1] != '\0' || i < DATA + 0 || i > DATA + 7))
  1191.     {
  1192.       opP->error = "Invalid indirect register";
  1193.       return FAIL;
  1194.     }
  1195.   know (*str == '@');
  1196.  
  1197.   str++;
  1198.   switch (*str)
  1199.     {
  1200.     case '\0':
  1201.       if (i < DATA + 0 || i > DATA + 7)
  1202.     opP->mode = AINDR;
  1203.       else
  1204.     opP->mode = DINDR;
  1205.       return OK;
  1206.     case '-':
  1207.       opP->mode = ADEC;
  1208.       return OK;
  1209.     case '+':
  1210.       opP->mode = AINC;
  1211.       return OK;
  1212.     case '(':
  1213.       str++;
  1214.       break;
  1215.     default:
  1216.       opP->error = "Junk after indirect";
  1217.       return FAIL;
  1218.     }
  1219.   /* Some kind of indexing involved.  Lets find out how bad it is */
  1220.   i = try_index (&str, opP);
  1221.   /* Didn't start with an index reg, maybe its offset or offset,reg */
  1222.   if (i == FAIL)
  1223.     {
  1224.       char *beg_str;
  1225.  
  1226.       beg_str = str;
  1227.       for (i = 1; i;)
  1228.     {
  1229.       switch (*str++)
  1230.         {
  1231.         case '\0':
  1232.           opP->error = "Missing )";
  1233.           return FAIL;
  1234.         case ',':
  1235.           i = 0;
  1236.           break;
  1237.         case '(':
  1238.           i++;
  1239.           break;
  1240.         case ')':
  1241.           --i;
  1242.           break;
  1243.         }
  1244.     }
  1245.       /* if(str[-3]==':') {
  1246.            int siz;
  1247.  
  1248.            switch(str[-2]) {
  1249.            case 'b':
  1250.            case 'B':
  1251.            siz=1;
  1252.            break;
  1253.            case 'w':
  1254.            case 'W':
  1255.            siz=2;
  1256.            break;
  1257.            case 'l':
  1258.            case 'L':
  1259.            siz=3;
  1260.            break;
  1261.            default:
  1262.            opP->error="Specified size isn't :w or :l";
  1263.            return FAIL;
  1264.            }
  1265.            opP->con1=add_exp(beg_str,str-4);
  1266.            opP->con1->e_siz=siz;
  1267.            } else */
  1268.       opP->con1 = add_exp (beg_str, str - 2);
  1269.       /* Should be offset,reg */
  1270.       if (str[-1] == ',')
  1271.     {
  1272.       i = try_index (&str, opP);
  1273.       if (i == FAIL)
  1274.         {
  1275.           opP->error = "Malformed index reg";
  1276.           return FAIL;
  1277.         }
  1278.     }
  1279.     }
  1280.   /* We've now got offset)   offset,reg)   or    reg) */
  1281.  
  1282.   if (*str == '\0')
  1283.     {
  1284.       /* Th-the-thats all folks */
  1285.       if (opP->reg == FAIL)
  1286.     opP->mode = AINDX;    /* Other form of indirect */
  1287.       else if (opP->ireg == FAIL)
  1288.     opP->mode = AOFF;
  1289.       else
  1290.     opP->mode = AINDX;
  1291.       return (OK);
  1292.     }
  1293.   /* Next thing had better be another @ */
  1294.   if (*str == '@')
  1295.     {
  1296.       if (str[1] == '(')
  1297.     {
  1298.       needp = 1;
  1299.       str += 2;
  1300.     }
  1301.       else
  1302.     {
  1303.       needp = 0;
  1304.       str++;
  1305.     }
  1306.     }
  1307.  
  1308.   if ((current_architecture & m68020up) == 0)
  1309.     {
  1310.       return (FAIL);
  1311.     }                /* if target is not a '20 or better */
  1312.  
  1313.  
  1314.   if (opP->ireg != FAIL)
  1315.     {
  1316.       opP->mode = APRDX;
  1317.  
  1318.       i = try_index (&str, opP);
  1319.       if (i != FAIL)
  1320.     {
  1321.       opP->error = "Two index registers!  not allowed!";
  1322.       return (FAIL);
  1323.     }
  1324.     }
  1325.   else
  1326.     {
  1327.       i = try_index (&str, opP);
  1328.     }
  1329.  
  1330.   if (i == FAIL)
  1331.     {
  1332.       char *beg_str;
  1333.  
  1334.       beg_str = str;
  1335.  
  1336.       for (i = 1; i;)
  1337.     {
  1338.       switch (*str++)
  1339.         {
  1340.         case '\0':
  1341.           if (needp)
  1342.         opP->error = "Missing )";
  1343.           return (FAIL);
  1344.           break;
  1345.         case ',':
  1346.           i = 0;
  1347.           break;
  1348.         case '(':
  1349.           i++;
  1350.           break;
  1351.         case ')':
  1352.           --i;
  1353.           break;
  1354.         }
  1355.     }
  1356.  
  1357.       opP->con2 = add_exp (beg_str, str - 2);
  1358.  
  1359.       if (str[-1] == ',')
  1360.     {
  1361.       if (opP->ireg != FAIL)
  1362.         {
  1363.           opP->error = "Can't have two index regs";
  1364.           return (FAIL);
  1365.         }
  1366.  
  1367.       i = try_index (&str, opP);
  1368.  
  1369.       if (i == FAIL)
  1370.         {
  1371.           opP->error = "malformed index reg";
  1372.           return (FAIL);
  1373.         }
  1374.  
  1375.       opP->mode = APODX;
  1376.     }
  1377.       else if (opP->ireg != FAIL)
  1378.     {
  1379.       opP->mode = APRDX;
  1380.     }
  1381.       else
  1382.     {
  1383.       opP->mode = AMIND;
  1384.     }
  1385.     }
  1386.   else
  1387.     {
  1388.       opP->mode = APODX;
  1389.     }
  1390.  
  1391.   if (*str != '\0')
  1392.     {
  1393.       opP->error = "Junk after indirect";
  1394.       return FAIL;
  1395.     }
  1396.   return (OK);
  1397. }                /* m68k_ip_op() */
  1398.  
  1399.  
  1400. #if defined (M68KCOFF) && !defined (BFD_ASSEMBLER)
  1401.  
  1402. short
  1403. tc_coff_fix2rtype (fixP)
  1404.      fixS *fixP;
  1405. {
  1406.   return (fixP->fx_pcrel ?
  1407.       (fixP->fx_size == 1 ? R_PCRBYTE :
  1408.        fixP->fx_size == 2 ? R_PCRWORD :
  1409.        R_PCRLONG) :
  1410.       (fixP->fx_size == 1 ? R_RELBYTE :
  1411.        fixP->fx_size == 2 ? R_RELWORD :
  1412.        R_RELLONG));
  1413.  
  1414.  
  1415. }
  1416.  
  1417. #endif
  1418.  
  1419. #ifdef BFD_ASSEMBLER
  1420.  
  1421. arelent *
  1422. tc_gen_reloc (section, fixp)
  1423.      asection *section;
  1424.      fixS *fixp;
  1425. {
  1426.   arelent *reloc;
  1427.   bfd_reloc_code_real_type code;
  1428.  
  1429. #define F(SZ,PCREL)        (((SZ) << 1) + (PCREL))
  1430.   switch (F (fixp->fx_size, fixp->fx_pcrel))
  1431.     {
  1432. #define MAP(SZ,PCREL,TYPE)    case F(SZ,PCREL): code = (TYPE); break
  1433.       MAP (1, 0, BFD_RELOC_8);
  1434.       MAP (2, 0, BFD_RELOC_16);
  1435.       MAP (4, 0, BFD_RELOC_32);
  1436.       MAP (1, 1, BFD_RELOC_8_PCREL);
  1437.       MAP (2, 1, BFD_RELOC_16_PCREL);
  1438.       MAP (4, 1, BFD_RELOC_32_PCREL);
  1439.     default:
  1440.       abort ();
  1441.     }
  1442.  
  1443.   reloc = (arelent *) bfd_alloc_by_size_t (stdoutput, sizeof (arelent));
  1444.   assert (reloc != 0);
  1445.   reloc->sym_ptr_ptr = &fixp->fx_addsy->bsym;
  1446.   reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
  1447.   if (fixp->fx_pcrel)
  1448.     reloc->addend = fixp->fx_addnumber;
  1449.   else
  1450.     reloc->addend = 0;
  1451.  
  1452.   reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
  1453.   assert (reloc->howto != 0);
  1454.  
  1455.   return reloc;
  1456. }
  1457.  
  1458. #endif /* BFD_ASSEMBLER */
  1459.  
  1460. #ifdef TEST1            /* TEST1 tests m68k_ip_op(), which parses operands */
  1461. main ()
  1462. {
  1463.   char buf[128];
  1464.   struct m68k_op thark;
  1465.  
  1466.   for (;;)
  1467.     {
  1468.       if (!gets (buf))
  1469.     break;
  1470.       memset (&thark, '\0', sizeof (thark));
  1471.       if (!m68k_ip_op (buf, &thark))
  1472.     printf ("FAIL:");
  1473.       if (thark.error)
  1474.     printf ("op1 error %s in %s\n", thark.error, buf);
  1475.       printf ("mode %d, reg %d, ", thark.mode, thark.reg);
  1476.       if (thark.b_const)
  1477.     printf ("Constant: '%.*s',", 1 + thark.e_const - thark.b_const, thark.b_const);
  1478.       printf ("ireg %d, isiz %d, imul %d ", thark.ireg, thark.isiz, thark.imul);
  1479.       if (thark.b_iadd)
  1480.     printf ("Iadd: '%.*s'", 1 + thark.e_iadd - thark.b_iadd, thark.b_iadd);
  1481.       printf ("\n");
  1482.     }
  1483.   exit (0);
  1484. }
  1485.  
  1486. #endif
  1487.  
  1488.  
  1489. /* Handle of the OPCODE hash table.  NULL means any use before
  1490.    m68k_ip_begin() will crash.  */
  1491. static struct hash_control *op_hash;
  1492.  
  1493.  
  1494. /*
  1495.  *        m 6 8 k _ i p ( )
  1496.  *
  1497.  * This converts a string into a 68k instruction.
  1498.  * The string must be a bare single instruction in sun format
  1499.  * with RMS-style 68020 indirects
  1500.  *  (example:  )
  1501.  *
  1502.  * It provides some error messages: at most one fatal error message (which
  1503.  * stops the scan) and at most one warning message for each operand.
  1504.  * The 68k instruction is returned in exploded form, since we have no
  1505.  * knowledge of how you parse (or evaluate) your expressions.
  1506.  * We do however strip off and decode addressing modes and operation
  1507.  * mnemonic.
  1508.  *
  1509.  * This function's value is a string. If it is not "" then an internal
  1510.  * logic error was found: read this code to assign meaning to the string.
  1511.  * No argument string should generate such an error string:
  1512.  * it means a bug in our code, not in the user's text.
  1513.  *
  1514.  * You MUST have called m68k_ip_begin() once and m86_ip_end() never before using
  1515.  * this function.
  1516.  */
  1517.  
  1518. /* JF this function no longer returns a useful value.  Sorry */
  1519. void
  1520. m68k_ip (instring)
  1521.      char *instring;
  1522. {
  1523.   register char *p;
  1524.   register struct m68k_op *opP;
  1525.   register struct m68k_incant *opcode;
  1526.   register char *s;
  1527.   register int tmpreg = 0, baseo = 0, outro = 0, nextword;
  1528.   char *pdot, *pdotmove;
  1529.   int siz1, siz2;
  1530.   char c;
  1531.   int losing;
  1532.   int opsfound;
  1533.   char *crack_operand ();
  1534.   LITTLENUM_TYPE words[6];
  1535.   LITTLENUM_TYPE *wordp;
  1536.   unsigned long ok_arch = 0;
  1537.  
  1538.   if (*instring == ' ')
  1539.     instring++;            /* skip leading whitespace */
  1540.  
  1541.   /* Scan up to end of operation-code, which MUST end in end-of-string
  1542.      or exactly 1 space. */
  1543.   pdot = 0;
  1544.   for (p = instring; *p != '\0'; p++)
  1545.     {
  1546.       if (*p == ' ')
  1547.     break;
  1548.       if (*p == '.')
  1549.     pdot = p;
  1550.     }
  1551.  
  1552.   if (p == instring)
  1553.     {
  1554.       the_ins.error = "No operator";
  1555.       the_ins.opcode[0] = NULL;
  1556.       /* the_ins.numo=1; */
  1557.       return;
  1558.     }
  1559.  
  1560.   /* p now points to the end of the opcode name, probably whitespace.
  1561.      make sure the name is null terminated by clobbering the whitespace,
  1562.      look it up in the hash table, then fix it back.
  1563.      Remove a dot, first, since the opcode tables have none.  */
  1564.   if (pdot != NULL)
  1565.     {
  1566.       for (pdotmove = pdot; pdotmove < p; pdotmove++)
  1567.     *pdotmove = pdotmove[1];
  1568.       p--;
  1569.     }
  1570.  
  1571.   c = *p;
  1572.   *p = '\0';
  1573.   opcode = (struct m68k_incant *) hash_find (op_hash, instring);
  1574.   *p = c;
  1575.  
  1576.   if (pdot != NULL)
  1577.     {
  1578.       for (pdotmove = p; pdotmove > pdot; pdotmove--)
  1579.     *pdotmove = pdotmove[-1];
  1580.       *pdot = '.';
  1581.       ++p;
  1582.     }
  1583.  
  1584.   if (opcode == NULL)
  1585.     {
  1586.       the_ins.error = "Unknown operator";
  1587.       the_ins.opcode[0] = NULL;
  1588.       /* the_ins.numo=1; */
  1589.       return;
  1590.     }
  1591.  
  1592.   /* found a legitimate opcode, start matching operands */
  1593.   while (*p == ' ')
  1594.     ++p;
  1595.  
  1596.  
  1597.   if (opcode->m_operands == 0)
  1598.     {
  1599.       char *old = input_line_pointer;
  1600.       *old = '\n';
  1601.       input_line_pointer = p;
  1602.       /* Ahh - it's a motorola style psuedo op */
  1603.       mote_pseudo_table[opcode->m_opnum].poc_handler
  1604.     (mote_pseudo_table[opcode->m_opnum].poc_val);
  1605.       input_line_pointer = old;
  1606.       *old = 0;
  1607.  
  1608.       return;
  1609.     }
  1610.  
  1611.   for (opP = &the_ins.operands[0]; *p; opP++)
  1612.     {
  1613.  
  1614.       p = crack_operand (p, opP);
  1615.  
  1616.       if (opP->error)
  1617.     {
  1618.       the_ins.error = opP->error;
  1619.       return;
  1620.     }
  1621.     }
  1622.  
  1623.   opsfound = opP - &the_ins.operands[0];
  1624.  
  1625.   /* This ugly hack is to support the floating pt opcodes in their standard form */
  1626.   /* Essentially, we fake a first enty of type COP#1 */
  1627.   if (opcode->m_operands[0] == 'I')
  1628.     {
  1629.       int n;
  1630.  
  1631.       for (n = opsfound; n > 0; --n)
  1632.     the_ins.operands[n] = the_ins.operands[n - 1];
  1633.  
  1634.       memset ((char *) (&the_ins.operands[0]), '\0', sizeof (the_ins.operands[0]));
  1635.       the_ins.operands[0].mode = MSCR;
  1636.       the_ins.operands[0].reg = COPNUM;    /* COP #1 */
  1637.       opsfound++;
  1638.     }
  1639.  
  1640.   /* We've got the operands.  Find an opcode that'll accept them */
  1641.   for (losing = 0;;)
  1642.     {
  1643.       /* If we didn't get the right number of ops, or we have no
  1644.      common model with this pattern then reject this pattern. */
  1645.  
  1646.       if (opsfound != opcode->m_opnum
  1647.       || ((opcode->m_arch & current_architecture) == 0))
  1648.     {
  1649.       ++losing;
  1650.       ok_arch |= opcode->m_arch;
  1651.     }
  1652.       else
  1653.     {
  1654.       for (s = opcode->m_operands, opP = &the_ins.operands[0]; *s && !losing; s += 2, opP++)
  1655.         {
  1656.           /* Warning: this switch is huge! */
  1657.           /* I've tried to organize the cases into this order:
  1658.          non-alpha first, then alpha by letter.  Lower-case
  1659.          goes directly before uppercase counterpart.  */
  1660.           /* Code with multiple case ...: gets sorted by the lowest
  1661.          case ... it belongs to.  I hope this makes sense.  */
  1662.           switch (*s)
  1663.         {
  1664.         case '!':
  1665.           if (opP->mode == MSCR || opP->mode == IMMED
  1666.               || opP->mode == DREG || opP->mode == AREG
  1667.               || opP->mode == AINC || opP->mode == ADEC
  1668.               || opP->mode == REGLST)
  1669.             losing++;
  1670.           break;
  1671.  
  1672.         case '`':
  1673.           switch (opP->mode)
  1674.             {
  1675.             case MSCR:
  1676.             case IMMED:
  1677.             case DREG:
  1678.             case AREG:
  1679.             case AINC:
  1680.             case REGLST:
  1681.             case AINDR:
  1682.               losing++;
  1683.             }
  1684.           break;
  1685.  
  1686.         case '#':
  1687.           if (opP->mode != IMMED)
  1688.             losing++;
  1689.           else
  1690.             {
  1691.               long t;
  1692.  
  1693.               t = get_num (opP->con1, 80);
  1694.               if (s[1] == 'b' && !isbyte (t))
  1695.             losing++;
  1696.               else if (s[1] == 'w' && !isword (t))
  1697.             losing++;
  1698.             }
  1699.           break;
  1700.  
  1701.         case '^':
  1702.         case 'T':
  1703.           if (opP->mode != IMMED)
  1704.             losing++;
  1705.           break;
  1706.  
  1707.         case '$':
  1708.           if (opP->mode == MSCR || opP->mode == AREG ||
  1709.               opP->mode == IMMED || opP->reg == PC || opP->reg == ZPC || opP->mode == REGLST)
  1710.             losing++;
  1711.           break;
  1712.  
  1713.         case '%':
  1714.           if (opP->mode == MSCR || opP->reg == PC ||
  1715.               opP->reg == ZPC || opP->mode == REGLST)
  1716.             losing++;
  1717.           break;
  1718.  
  1719.  
  1720.         case '&':
  1721.           if (opP->mode == MSCR || opP->mode == DREG ||
  1722.               opP->mode == AREG || opP->mode == IMMED || opP->reg == PC || opP->reg == ZPC ||
  1723.               opP->mode == AINC || opP->mode == ADEC || opP->mode == REGLST)
  1724.             losing++;
  1725.           break;
  1726.  
  1727.         case '*':
  1728.           if (opP->mode == MSCR || opP->mode == REGLST)
  1729.             losing++;
  1730.           break;
  1731.  
  1732.         case '+':
  1733.           if (opP->mode != AINC)
  1734.             losing++;
  1735.           break;
  1736.  
  1737.         case '-':
  1738.           if (opP->mode != ADEC)
  1739.             losing++;
  1740.           break;
  1741.  
  1742.         case '/':
  1743.           if (opP->mode == MSCR || opP->mode == AREG ||
  1744.               opP->mode == AINC || opP->mode == ADEC || opP->mode == IMMED || opP->mode == REGLST)
  1745.             losing++;
  1746.           break;
  1747.  
  1748.         case ';':
  1749.           if (opP->mode == MSCR || opP->mode == AREG || opP->mode == REGLST)
  1750.             losing++;
  1751.           break;
  1752.  
  1753.         case '?':
  1754.           if (opP->mode == MSCR || opP->mode == AREG ||
  1755.               opP->mode == AINC || opP->mode == ADEC || opP->mode == IMMED || opP->reg == PC ||
  1756.               opP->reg == ZPC || opP->mode == REGLST)
  1757.             losing++;
  1758.           break;
  1759.  
  1760.         case '@':
  1761.           if (opP->mode == MSCR || opP->mode == AREG ||
  1762.               opP->mode == IMMED || opP->mode == REGLST)
  1763.             losing++;
  1764.           break;
  1765.  
  1766.         case '~':    /* For now! (JF FOO is this right?) */
  1767.           if (opP->mode == MSCR || opP->mode == DREG ||
  1768.               opP->mode == AREG || opP->mode == IMMED || opP->reg == PC || opP->reg == ZPC || opP->mode == REGLST)
  1769.             losing++;
  1770.           break;
  1771.  
  1772.         case '3':
  1773.           if (opP->mode != MSCR || (opP->reg != TT0 && opP->reg != TT1))
  1774.             losing++;
  1775.           break;
  1776.  
  1777.         case 'A':
  1778.           if (opP->mode != AREG)
  1779.             losing++;
  1780.           break;
  1781.         case 'a':
  1782.           if (opP->mode != AINDR)
  1783.             {
  1784.               ++losing;
  1785.             }        /* if not address register indirect */
  1786.           break;
  1787.         case 'B':    /* FOO */
  1788.           if (opP->mode != ABSL || (flagseen['S'] && instring[0] == 'j'
  1789.                         && instring[1] == 'b'
  1790.                         && instring[2] == 's'
  1791.                         && instring[3] == 'r'))
  1792.             losing++;
  1793.           break;
  1794.  
  1795.         case 'C':
  1796.           if (opP->mode != MSCR || opP->reg != CCR)
  1797.             losing++;
  1798.           break;
  1799.  
  1800.         case 'd':    /* FOO This mode is a KLUDGE!! */
  1801.           if (opP->mode != AOFF && (opP->mode != ABSL ||
  1802.           opP->con1->e_beg[0] != '(' || opP->con1->e_end[0] != ')'))
  1803.             losing++;
  1804.           break;
  1805.  
  1806.         case 'D':
  1807.           if (opP->mode != DREG)
  1808.             losing++;
  1809.           break;
  1810.  
  1811.         case 'F':
  1812.           if (opP->mode != MSCR || opP->reg < (FPREG + 0) || opP->reg > (FPREG + 7))
  1813.             losing++;
  1814.           break;
  1815.  
  1816.         case 'I':
  1817.           if (opP->mode != MSCR || opP->reg < COPNUM ||
  1818.               opP->reg >= COPNUM + 7)
  1819.             losing++;
  1820.           break;
  1821.  
  1822.         case 'J':
  1823.           if (opP->mode != MSCR
  1824.               || opP->reg < USP
  1825.               || opP->reg > URP
  1826.               || cpu_of_arch (current_architecture) < m68010    /* before 68010 had none */
  1827.               || (cpu_of_arch (current_architecture) < m68020
  1828.               && opP->reg != SFC
  1829.               && opP->reg != DFC
  1830.               && opP->reg != USP
  1831.               && opP->reg != VBR)    /* 68010's had only these */
  1832.               || (cpu_of_arch (current_architecture) < m68040
  1833.               && opP->reg != SFC
  1834.               && opP->reg != DFC
  1835.               && opP->reg != USP
  1836.               && opP->reg != VBR
  1837.               && opP->reg != CACR
  1838.               && opP->reg != CAAR
  1839.               && opP->reg != MSP
  1840.               && opP->reg != ISP)    /* 680[23]0's have only these */
  1841.               || (cpu_of_arch (current_architecture) == m68040    /* 68040 has all but this */
  1842.               && opP->reg == CAAR))
  1843.             {
  1844.               losing++;
  1845.             }        /* doesn't cut it */
  1846.           break;
  1847.  
  1848.         case 'k':
  1849.           if (opP->mode != IMMED)
  1850.             losing++;
  1851.           break;
  1852.  
  1853.         case 'l':
  1854.         case 'L':
  1855.           if (opP->mode == DREG || opP->mode == AREG || opP->mode == FPREG)
  1856.             {
  1857.               if (s[1] == '8')
  1858.             losing++;
  1859.               else
  1860.             {
  1861.               opP->mode = REGLST;
  1862.               opP->reg = 1 << (opP->reg - DATA);
  1863.             }
  1864.             }
  1865.           else if (opP->mode != REGLST)
  1866.             {
  1867.               losing++;
  1868.             }
  1869.           else if (s[1] == '8' && opP->reg & 0x0FFffFF)
  1870.             losing++;
  1871.           else if (s[1] == '3' && opP->reg & 0x7000000)
  1872.             losing++;
  1873.           break;
  1874.  
  1875.         case 'M':
  1876.           if (opP->mode != IMMED)
  1877.             losing++;
  1878.           else
  1879.             {
  1880.               long t;
  1881.  
  1882.               t = get_num (opP->con1, 0);
  1883.               if (!issbyte (t)
  1884.               || isvar (opP->con1)
  1885.               || seg (opP->con1) != absolute_section)
  1886.             losing++;
  1887.             }
  1888.           break;
  1889.  
  1890.         case 'O':
  1891.           if (opP->mode != DREG && opP->mode != IMMED)
  1892.             losing++;
  1893.           break;
  1894.  
  1895.         case 'Q':
  1896.           if (opP->mode != IMMED)
  1897.             losing++;
  1898.           else
  1899.             {
  1900.               long t;
  1901.  
  1902.               t = get_num (opP->con1, 80);
  1903.               if (t < 1 || t > 8 || isvar (opP->con1))
  1904.             losing++;
  1905.             }
  1906.           break;
  1907.  
  1908.         case 'R':
  1909.           if (opP->mode != DREG && opP->mode != AREG)
  1910.             losing++;
  1911.           break;
  1912.  
  1913.         case 'r':
  1914.           if (opP->mode != AINDR && opP->mode != DINDR)
  1915.             losing++;
  1916.           break;
  1917.  
  1918.         case 's':
  1919.           if (opP->mode != MSCR || !(opP->reg == FPI || opP->reg == FPS || opP->reg == FPC))
  1920.             losing++;
  1921.           break;
  1922.  
  1923.         case 'S':
  1924.           if (opP->mode != MSCR || opP->reg != SR)
  1925.             losing++;
  1926.           break;
  1927.  
  1928.         case 't':
  1929.           if (opP->mode != IMMED)
  1930.             losing++;
  1931.           else
  1932.             {
  1933.               long t = get_num (opP->con1, 80);
  1934.               if (t < 0 || t > 7 || isvar (opP->con1))
  1935.             losing++;
  1936.             }
  1937.           break;
  1938.  
  1939.         case 'U':
  1940.           if (opP->mode != MSCR || opP->reg != USP)
  1941.             losing++;
  1942.           break;
  1943.  
  1944.           /* JF these are out of order.  We could put them
  1945.              in order if we were willing to put up with
  1946.              bunches of #ifdef m68851s in the code.
  1947.  
  1948.              Don't forget that you need these operands
  1949.              to use 68030 MMU instructions.  */
  1950. #ifndef NO_68851
  1951.           /* Memory addressing mode used by pflushr */
  1952.         case '|':
  1953.           if (opP->mode == MSCR || opP->mode == DREG ||
  1954.               opP->mode == AREG || opP->mode == REGLST)
  1955.             losing++;
  1956.           break;
  1957.  
  1958.         case 'f':
  1959.           if (opP->mode != MSCR || (opP->reg != SFC && opP->reg != DFC))
  1960.             losing++;
  1961.           break;
  1962.  
  1963.         case 'P':
  1964.           if (opP->mode != MSCR
  1965.               || (opP->reg != TC && opP->reg != CAL
  1966.            && opP->reg != VAL && opP->reg != SCC && opP->reg != AC))
  1967.             losing++;
  1968.           break;
  1969.  
  1970.         case 'V':
  1971.           if (opP->reg != VAL)
  1972.             losing++;
  1973.           break;
  1974.  
  1975.         case 'W':
  1976.           if (opP->mode != MSCR
  1977.               || (opP->reg != DRP && opP->reg != SRP
  1978.               && opP->reg != CRP))
  1979.             losing++;
  1980.           break;
  1981.  
  1982.         case 'X':
  1983.           if (opP->mode != MSCR ||
  1984.               (!(opP->reg >= BAD && opP->reg <= BAD + 7) &&
  1985.                !(opP->reg >= BAC && opP->reg <= BAC + 7)))
  1986.             losing++;
  1987.           break;
  1988.  
  1989.         case 'Y':
  1990.           if (opP->reg != PSR)
  1991.             losing++;
  1992.           break;
  1993.  
  1994.         case 'Z':
  1995.           if (opP->reg != PCSR)
  1996.             losing++;
  1997.           break;
  1998. #endif
  1999.         case 'c':
  2000.           if (opP->reg != NC
  2001.               && opP->reg != IC
  2002.               && opP->reg != DC
  2003.               && opP->reg != BC)
  2004.             {
  2005.               losing++;
  2006.             }        /* not a cache specifier. */
  2007.           break;
  2008.  
  2009.         case '_':
  2010.           if (opP->mode != ABSL)
  2011.             {
  2012.               ++losing;
  2013.             }        /* not absolute */
  2014.           break;
  2015.  
  2016.         default:
  2017.           as_fatal ("Internal error:  Operand mode %c unknown in line %d of file \"%s\"",
  2018.                 *s, __LINE__, __FILE__);
  2019.         }        /* switch on type of operand */
  2020.  
  2021.           if (losing)
  2022.         break;
  2023.         }            /* for each operand */
  2024.     }            /* if immediately wrong */
  2025.  
  2026.       if (!losing)
  2027.     {
  2028.       break;
  2029.     }            /* got it. */
  2030.  
  2031.       opcode = opcode->m_next;
  2032.  
  2033.       if (!opcode)
  2034.     {
  2035.       if (ok_arch
  2036.           && !(ok_arch & current_architecture))
  2037.         {
  2038.           char buf[200], *cp;
  2039.           int len;
  2040.           strcpy (buf, "invalid instruction for this architecture; needs ");
  2041.           cp = buf + strlen (buf);
  2042.           switch (ok_arch)
  2043.         {
  2044.         case mfloat:
  2045.           strcpy (cp, "fpu (68040 or 68881/68882)");
  2046.           break;
  2047.         case mmmu:
  2048.           strcpy (cp, "mmu (68030 or 68851)");
  2049.           break;
  2050.         case m68020up:
  2051.           strcpy (cp, "68020 or higher");
  2052.           break;
  2053.         case m68000up:
  2054.           strcpy (cp, "68000 or higher");
  2055.           break;
  2056.         case m68010up:
  2057.           strcpy (cp, "68010 or higher");
  2058.           break;
  2059.         default:
  2060.           {
  2061.             int got_one = 0, idx;
  2062.             CONST static struct
  2063.               {
  2064.             int arch;
  2065.             CONST char *name;
  2066.               }
  2067.             archs[] =
  2068.             {
  2069.               m68000, "68000",
  2070.               m68010, "68010",
  2071.               m68020, "68020",
  2072.               m68030, "68030",
  2073.               m68040, "68040",
  2074.               cpu32,  "cpu32",
  2075.               m68881, "68881",
  2076.               m68851, "68851",
  2077.             };
  2078.             for (idx = 0; idx < sizeof (archs) / sizeof (archs[0]); idx++)
  2079.               {
  2080.             if (archs[idx].arch & ok_arch)
  2081.               {
  2082.                 if (got_one)
  2083.                   {
  2084.                 strcpy (cp, " or ");
  2085.                 cp += strlen (cp);
  2086.                   }
  2087.                 got_one = 1;
  2088.                 strcpy (cp, archs[idx].name);
  2089.                 cp += strlen (cp);
  2090.               }
  2091.               }
  2092.           }
  2093.         }
  2094.           len = cp - buf + 1;
  2095.           cp = malloc (len);
  2096.           strcpy (cp, buf);
  2097.           the_ins.error = cp;
  2098.         }
  2099.       else
  2100.         the_ins.error = "operands mismatch";
  2101.       return;
  2102.     }            /* Fell off the end */
  2103.  
  2104.       losing = 0;
  2105.     }
  2106.  
  2107.   /* now assemble it */
  2108.  
  2109.   the_ins.args = opcode->m_operands;
  2110.   the_ins.numargs = opcode->m_opnum;
  2111.   the_ins.numo = opcode->m_codenum;
  2112.   the_ins.opcode[0] = getone (opcode);
  2113.   the_ins.opcode[1] = gettwo (opcode);
  2114.  
  2115.   for (s = the_ins.args, opP = &the_ins.operands[0]; *s; s += 2, opP++)
  2116.     {
  2117.       /* This switch is a doozy.
  2118.        Watch the first step; its a big one! */
  2119.       switch (s[0])
  2120.     {
  2121.  
  2122.     case '*':
  2123.     case '~':
  2124.     case '%':
  2125.     case ';':
  2126.     case '@':
  2127.     case '!':
  2128.     case '&':
  2129.     case '$':
  2130.     case '?':
  2131.     case '/':
  2132.     case '`':
  2133. #ifndef NO_68851
  2134.     case '|':
  2135. #endif
  2136.       switch (opP->mode)
  2137.         {
  2138.         case IMMED:
  2139.           tmpreg = 0x3c;    /* 7.4 */
  2140.           if (strchr ("bwl", s[1]))
  2141.         nextword = get_num (opP->con1, 80);
  2142.           else
  2143.         nextword = get_num (opP->con1, 0);
  2144.           if (isvar (opP->con1))
  2145.         add_fix (s[1], opP->con1, 0);
  2146.           switch (s[1])
  2147.         {
  2148.         case 'b':
  2149.           if (!isbyte (nextword))
  2150.             opP->error = "operand out of range";
  2151.           addword (nextword);
  2152.           baseo = 0;
  2153.           break;
  2154.         case 'w':
  2155.           if (!isword (nextword))
  2156.             opP->error = "operand out of range";
  2157.           addword (nextword);
  2158.           baseo = 0;
  2159.           break;
  2160.         case 'l':
  2161.           addword (nextword >> 16);
  2162.           addword (nextword);
  2163.           baseo = 0;
  2164.           break;
  2165.  
  2166.         case 'f':
  2167.           baseo = 2;
  2168.           outro = 8;
  2169.           break;
  2170.         case 'F':
  2171.           baseo = 4;
  2172.           outro = 11;
  2173.           break;
  2174.         case 'x':
  2175.           baseo = 6;
  2176.           outro = 15;
  2177.           break;
  2178.         case 'p':
  2179.           baseo = 6;
  2180.           outro = -1;
  2181.           break;
  2182.         default:
  2183.           as_fatal ("Internal error:  Can't decode %c%c in line %s of file \"%s\"",
  2184.                 *s, s[1], __LINE__, __FILE__);
  2185.         }
  2186.           if (!baseo)
  2187.         break;
  2188.  
  2189.           /* We gotta put out some float */
  2190. #if 0
  2191.           if (seg (opP->con1) != SEG_BIG)
  2192.         {
  2193.           int_to_gen (nextword);
  2194.           gen_to_words (words, baseo, (long int) outro);
  2195.           for (wordp = words; baseo--; wordp++)
  2196.             addword (*wordp);
  2197.           break;
  2198.         }        /* Its BIG */
  2199. #else
  2200.           if (seg (opP->con1) != big_section)
  2201.         {
  2202.           abort ();
  2203.         }
  2204. #endif
  2205.           if (offs (opP->con1) > 0)
  2206.         {
  2207.           if (offs (opP->con1) > baseo)
  2208.             {
  2209.               as_warn ("Bignum too big for %c format; truncated", s[1]);
  2210.               offs (opP->con1) = baseo;
  2211.             }
  2212.           baseo -= offs (opP->con1);
  2213.           for (wordp = generic_bignum + offs (opP->con1) - 1; offs (opP->con1)--; --wordp)
  2214.             addword (*wordp);
  2215.           while (baseo--)
  2216.             addword (0);
  2217.           break;
  2218.         }
  2219.           gen_to_words (words, baseo, (long) outro);
  2220.           for (wordp = words; baseo--; wordp++)
  2221.         addword (*wordp);
  2222.           break;
  2223.         case DREG:
  2224.           tmpreg = opP->reg - DATA;    /* 0.dreg */
  2225.           break;
  2226.         case AREG:
  2227.           tmpreg = 0x08 + opP->reg - ADDR;    /* 1.areg */
  2228.           break;
  2229.         case AINDR:
  2230.           tmpreg = 0x10 + opP->reg - ADDR;    /* 2.areg */
  2231.           break;
  2232.         case ADEC:
  2233.           tmpreg = 0x20 + opP->reg - ADDR;    /* 4.areg */
  2234.           break;
  2235.         case AINC:
  2236.           tmpreg = 0x18 + opP->reg - ADDR;    /* 3.areg */
  2237.           break;
  2238.         case AOFF:
  2239.  
  2240.           nextword = get_num (opP->con1, 80);
  2241.           /* Force into index mode.  Hope this works */
  2242.  
  2243.           /* We do the first bit for 32-bit displacements, and the
  2244.          second bit for 16 bit ones.  It is possible that we
  2245.          should make the default be WORD instead of LONG, but
  2246.          I think that'd break GCC, so we put up with a little
  2247.          inefficiency for the sake of working output.  */
  2248.  
  2249.           if (!issword (nextword)
  2250.           || (isvar (opP->con1)
  2251.               && ((opP->con1->e_siz == 0
  2252.                && flagseen['l'] == 0)
  2253.               || opP->con1->e_siz == 3)))
  2254.         {
  2255.  
  2256.           if (opP->reg == PC)
  2257.             tmpreg = 0x3B;    /* 7.3 */
  2258.           else
  2259.             tmpreg = 0x30 + opP->reg - ADDR;    /* 6.areg */
  2260.           if (isvar (opP->con1))
  2261.             {
  2262.               if (opP->reg == PC)
  2263.             {
  2264.               add_frag (adds (opP->con1),
  2265.                     offs (opP->con1) + 2,
  2266.                     TAB (PCLEA, SZ_UNDEF));
  2267.               break;
  2268.             }
  2269.               else
  2270.             {
  2271.               addword (0x0170);
  2272.               add_fix ('l', opP->con1, 0);
  2273.             }
  2274.             }
  2275.           else
  2276.             addword (0x0170);
  2277.           addword (nextword >> 16);
  2278.         }
  2279.           else
  2280.         {
  2281.           if (opP->reg == PC)
  2282.             tmpreg = 0x3A;    /* 7.2 */
  2283.           else
  2284.             tmpreg = 0x28 + opP->reg - ADDR;    /* 5.areg */
  2285.  
  2286.           if (isvar (opP->con1))
  2287.             {
  2288.               if (opP->reg == PC)
  2289.             {
  2290.               add_fix ('w', opP->con1, 1);
  2291.             }
  2292.               else
  2293.             add_fix ('w', opP->con1, 0);
  2294.             }
  2295.         }
  2296.           addword (nextword);
  2297.           break;
  2298.  
  2299.         case APODX:
  2300.         case AMIND:
  2301.         case APRDX:
  2302.           know (current_architecture & m68020up);
  2303.           /* intentional fall-through */
  2304.         case AINDX:
  2305.           nextword = 0;
  2306.           baseo = get_num (opP->con1, 80);
  2307.           outro = get_num (opP->con2, 80);
  2308.           /* Figure out the `addressing mode'.
  2309.          Also turn on the BASE_DISABLE bit, if needed.  */
  2310.           if (opP->reg == PC || opP->reg == ZPC)
  2311.         {
  2312.           tmpreg = 0x3b;/* 7.3 */
  2313.           if (opP->reg == ZPC)
  2314.             nextword |= 0x80;
  2315.         }
  2316.           else if (opP->reg == FAIL)
  2317.         {
  2318.           nextword |= 0x80;
  2319.           tmpreg = 0x30;/* 6.garbage */
  2320.         }
  2321.           else
  2322.         tmpreg = 0x30 + opP->reg - ADDR;    /* 6.areg */
  2323.  
  2324.           siz1 = (opP->con1) ? opP->con1->e_siz : 0;
  2325.           siz2 = (opP->con2) ? opP->con2->e_siz : 0;
  2326.  
  2327.           /* Index register stuff */
  2328.           if (opP->ireg >= DATA + 0 && opP->ireg <= ADDR + 7)
  2329.         {
  2330.           nextword |= (opP->ireg - DATA) << 12;
  2331.  
  2332.           if (opP->isiz == 0 || opP->isiz == 3)
  2333.             nextword |= 0x800;
  2334.           switch (opP->imul)
  2335.             {
  2336.             case 1:
  2337.               break;
  2338.             case 2:
  2339.               nextword |= 0x200;
  2340.               break;
  2341.             case 4:
  2342.               nextword |= 0x400;
  2343.               break;
  2344.             case 8:
  2345.               nextword |= 0x600;
  2346.               break;
  2347.             default:
  2348.               as_fatal ("failed sanity check.");
  2349.             }
  2350.           /* IF its simple,
  2351.              GET US OUT OF HERE! */
  2352.  
  2353.           /* Must be INDEX, with an index
  2354.              register.  Address register
  2355.              cannot be ZERO-PC, and either
  2356.              :b was forced, or we know
  2357.              it will fit */
  2358.           if (opP->mode == AINDX
  2359.               && opP->reg != FAIL
  2360.               && opP->reg != ZPC
  2361.               && (siz1 == 1
  2362.               || (issbyte (baseo)
  2363.                   && !isvar (opP->con1))))
  2364.             {
  2365.               nextword += baseo & 0xff;
  2366.               addword (nextword);
  2367.               if (isvar (opP->con1))
  2368.             add_fix ('B', opP->con1, 0);
  2369.               break;
  2370.             }
  2371.         }
  2372.           else
  2373.         nextword |= 0x40;    /* No index reg */
  2374.  
  2375.           /* It isn't simple.  */
  2376.           nextword |= 0x100;
  2377.           /* If the guy specified a width, we assume that it is
  2378.          wide enough.  Maybe it isn't.  If so, we lose.  */
  2379.           switch (siz1)
  2380.         {
  2381.         case 0:
  2382.           if (isvar (opP->con1) || !issword (baseo))
  2383.             {
  2384.               siz1 = 3;
  2385.               nextword |= 0x30;
  2386.             }
  2387.           else if (baseo == 0)
  2388.             nextword |= 0x10;
  2389.           else
  2390.             {
  2391.               nextword |= 0x20;
  2392.               siz1 = 2;
  2393.             }
  2394.           break;
  2395.         case 1:
  2396.           as_warn ("Byte dispacement won't work.  Defaulting to :w");
  2397.         case 2:
  2398.           nextword |= 0x20;
  2399.           break;
  2400.         case 3:
  2401.           nextword |= 0x30;
  2402.           break;
  2403.         }
  2404.  
  2405.           /* Figure out innner displacement stuff */
  2406.           if (opP->mode != AINDX)
  2407.         {
  2408.           switch (siz2)
  2409.             {
  2410.             case 0:
  2411.               if (isvar (opP->con2) || !issword (outro))
  2412.             {
  2413.               siz2 = 3;
  2414.               nextword |= 0x3;
  2415.             }
  2416.               else if (outro == 0)
  2417.             nextword |= 0x1;
  2418.               else
  2419.             {
  2420.               nextword |= 0x2;
  2421.               siz2 = 2;
  2422.             }
  2423.               break;
  2424.             case 1:
  2425.               as_warn ("Byte dispacement won't work.  Defaulting to :w");
  2426.             case 2:
  2427.               nextword |= 0x2;
  2428.               break;
  2429.             case 3:
  2430.               nextword |= 0x3;
  2431.               break;
  2432.             }
  2433.           if (opP->mode == APODX)
  2434.             nextword |= 0x04;
  2435.           else if (opP->mode == AMIND)
  2436.             nextword |= 0x40;
  2437.         }
  2438.           addword (nextword);
  2439.  
  2440.           if (isvar (opP->con1))
  2441.         {
  2442.           if (opP->reg == PC || opP->reg == ZPC)
  2443.             {
  2444.               add_fix (siz1 == 3 ? 'l' : 'w', opP->con1, 1);
  2445.               opP->con1->e_exp.X_add_number += 6;
  2446.             }
  2447.           else
  2448.             add_fix (siz1 == 3 ? 'l' : 'w', opP->con1, 0);
  2449.         }
  2450.           if (siz1 == 3)
  2451.         addword (baseo >> 16);
  2452.           if (siz1)
  2453.         addword (baseo);
  2454.  
  2455.           if (isvar (opP->con2))
  2456.         {
  2457.           if (opP->reg == PC || opP->reg == ZPC)
  2458.             {
  2459.               add_fix (siz2 == 3 ? 'l' : 'w', opP->con2, 1);
  2460.               opP->con1->e_exp.X_add_number += 6;
  2461.             }
  2462.           else
  2463.             add_fix (siz2 == 3 ? 'l' : 'w', opP->con2, 0);
  2464.         }
  2465.           if (siz2 == 3)
  2466.         addword (outro >> 16);
  2467.           if (siz2)
  2468.         addword (outro);
  2469.  
  2470.           break;
  2471.  
  2472.         case ABSL:
  2473.           nextword = get_num (opP->con1, 80);
  2474.           switch (opP->con1->e_siz)
  2475.         {
  2476.         default:
  2477.           as_warn ("Unknown size for absolute reference");
  2478.         case 0:
  2479.           if (!isvar (opP->con1) && issword (offs (opP->con1)))
  2480.             {
  2481.               tmpreg = 0x38;    /* 7.0 */
  2482.               addword (nextword);
  2483.               break;
  2484.             }
  2485.           /* Don't generate pc relative code
  2486.          on 68010 and 68000 */
  2487.           if (isvar (opP->con1)
  2488.               && !subs (opP->con1)
  2489.               && seg (opP->con1) == text_section
  2490.               && now_seg == text_section
  2491.               && cpu_of_arch (current_architecture) >= m68020
  2492.               && !flagseen['S']
  2493.               && !strchr ("~%&$?", s[0]))
  2494.             {
  2495.               tmpreg = 0x3A;    /* 7.2 */
  2496.               add_frag (adds (opP->con1),
  2497.                 offs (opP->con1),
  2498.                 TAB (PCREL, SZ_UNDEF));
  2499.               break;
  2500.             }
  2501.         case 3:    /* Fall through into long */
  2502.           if (isvar (opP->con1))
  2503.             add_fix ('l', opP->con1, 0);
  2504.  
  2505.           tmpreg = 0x39;/* 7.1 mode */
  2506.           addword (nextword >> 16);
  2507.           addword (nextword);
  2508.           break;
  2509.  
  2510.         case 2:    /* Word */
  2511.           if (isvar (opP->con1))
  2512.             add_fix ('w', opP->con1, 0);
  2513.  
  2514.           tmpreg = 0x38;/* 7.0 mode */
  2515.           addword (nextword);
  2516.           break;
  2517.         }
  2518.           break;
  2519.         case DINDR:
  2520.           as_bad ("invalid indirect register");
  2521.           break;
  2522.         case MSCR:
  2523.         default:
  2524.           as_bad ("unknown/incorrect operand");
  2525.           /* abort(); */
  2526.         }
  2527.       install_gen_operand (s[1], tmpreg);
  2528.       break;
  2529.  
  2530.     case '#':
  2531.     case '^':
  2532.       switch (s[1])
  2533.         {            /* JF: I hate floating point! */
  2534.         case 'j':
  2535.           tmpreg = 70;
  2536.           break;
  2537.         case '8':
  2538.           tmpreg = 20;
  2539.           break;
  2540.         case 'C':
  2541.           tmpreg = 50;
  2542.           break;
  2543.         case '3':
  2544.         default:
  2545.           tmpreg = 80;
  2546.           break;
  2547.         }
  2548.       tmpreg = get_num (opP->con1, tmpreg);
  2549.       if (isvar (opP->con1))
  2550.         add_fix (s[1], opP->con1, 0);
  2551.       switch (s[1])
  2552.         {
  2553.         case 'b':        /* Danger:  These do no check for
  2554.                    certain types of overflow.
  2555.                    user beware! */
  2556.           if (!isbyte (tmpreg))
  2557.         opP->error = "out of range";
  2558.           insop (tmpreg);
  2559.           if (isvar (opP->con1))
  2560.         the_ins.reloc[the_ins.nrel - 1].n = (opcode->m_codenum) * 2;
  2561.           break;
  2562.         case 'w':
  2563.           if (!isword (tmpreg))
  2564.         opP->error = "out of range";
  2565.           insop (tmpreg);
  2566.           if (isvar (opP->con1))
  2567.         the_ins.reloc[the_ins.nrel - 1].n = (opcode->m_codenum) * 2;
  2568.           break;
  2569.         case 'l':
  2570.           insop (tmpreg);    /* Because of the way insop works, we put these two out backwards */
  2571.           insop (tmpreg >> 16);
  2572.           if (isvar (opP->con1))
  2573.         the_ins.reloc[the_ins.nrel - 1].n = (opcode->m_codenum) * 2;
  2574.           break;
  2575.         case '3':
  2576.           tmpreg &= 0xFF;
  2577.         case '8':
  2578.         case 'C':
  2579.           install_operand (s[1], tmpreg);
  2580.           break;
  2581.         default:
  2582.           as_fatal ("Internal error:  Unknown mode #%c in line %s of file \"%s\"", s[1], __LINE__, __FILE__);
  2583.         }
  2584.       break;
  2585.  
  2586.     case '+':
  2587.     case '-':
  2588.     case 'A':
  2589.     case 'a':
  2590.       install_operand (s[1], opP->reg - ADDR);
  2591.       break;
  2592.  
  2593.     case 'B':
  2594.       tmpreg = get_num (opP->con1, 80);
  2595.       switch (s[1])
  2596.         {
  2597.         case 'B':
  2598.           /* Needs no offsetting */
  2599.           add_fix ('B', opP->con1, 1);
  2600.           break;
  2601.         case 'W':
  2602.           /* Offset the displacement to be relative to byte disp location */
  2603.           opP->con1->e_exp.X_add_number += 2;
  2604.           add_fix ('w', opP->con1, 1);
  2605.           addword (0);
  2606.           break;
  2607.         case 'L':
  2608.         long_branch:
  2609.           if (cpu_of_arch (current_architecture) < m68020)    /* 68000 or 010 */
  2610.         as_warn ("Can't use long branches on 68000/68010");
  2611.           the_ins.opcode[the_ins.numo - 1] |= 0xff;
  2612.           /* Offset the displacement to be relative to byte disp location */
  2613.           opP->con1->e_exp.X_add_number += 4;
  2614.           add_fix ('l', opP->con1, 1);
  2615.           addword (0);
  2616.           addword (0);
  2617.           break;
  2618.         case 'g':
  2619.           if (subs (opP->con1))    /* We can't relax it */
  2620.         goto long_branch;
  2621.  
  2622.           /* This could either be a symbol, or an
  2623.          absolute address.  No matter, the
  2624.          frag hacking will finger it out.
  2625.          Not quite: it can't switch from
  2626.          BRANCH to BCC68000 for the case
  2627.          where opnd is absolute (it needs
  2628.          to use the 68000 hack since no
  2629.          conditional abs jumps).  */
  2630.           if (((cpu_of_arch (current_architecture) < m68020) || (0 == adds (opP->con1)))
  2631.           && (the_ins.opcode[0] >= 0x6200)
  2632.           && (the_ins.opcode[0] <= 0x6f00))
  2633.         {
  2634.           add_frag (adds (opP->con1), offs (opP->con1), TAB (BCC68000, SZ_UNDEF));
  2635.         }
  2636.           else
  2637.         {
  2638.           add_frag (adds (opP->con1), offs (opP->con1), TAB (ABRANCH, SZ_UNDEF));
  2639.         }
  2640.           break;
  2641.         case 'w':
  2642.           if (isvar (opP->con1))
  2643.         {
  2644. #if 0
  2645.           /* check for DBcc instruction */
  2646.           if ((the_ins.opcode[0] & 0xf0f8) == 0x50c8)
  2647.             {
  2648.               /* size varies if patch */
  2649.               /* needed for long form */
  2650.               add_frag (adds (opP->con1), offs (opP->con1), TAB (DBCC, SZ_UNDEF));
  2651.               break;
  2652.             }
  2653. #endif
  2654.           /* Don't ask! */
  2655.           opP->con1->e_exp.X_add_number += 2;
  2656.           add_fix ('w', opP->con1, 1);
  2657.         }
  2658.           addword (0);
  2659.           break;
  2660.         case 'C':        /* Fixed size LONG coproc branches */
  2661.           the_ins.opcode[the_ins.numo - 1] |= 0x40;
  2662.           /* Offset the displacement to be relative to byte disp location */
  2663.           /* Coproc branches don't have a byte disp option, but they are
  2664.        compatible with the ordinary branches, which do... */
  2665.           opP->con1->e_exp.X_add_number += 4;
  2666.           add_fix ('l', opP->con1, 1);
  2667.           addword (0);
  2668.           addword (0);
  2669.           break;
  2670.         case 'c':        /* Var size Coprocesssor branches */
  2671.           if (subs (opP->con1))
  2672.         {
  2673.           add_fix ('l', opP->con1, 1);
  2674.           add_frag ((symbolS *) 0, (long) 0, TAB (FBRANCH, LONG));
  2675.         }
  2676.           else if (adds (opP->con1))
  2677.         {
  2678.           add_frag (adds (opP->con1), offs (opP->con1), TAB (FBRANCH, SZ_UNDEF));
  2679.         }
  2680.           else
  2681.         {
  2682.           /* add_frag((symbolS *)0,offs(opP->con1),TAB(FBRANCH,SHORT)); */
  2683.           the_ins.opcode[the_ins.numo - 1] |= 0x40;
  2684.           add_fix ('l', opP->con1, 1);
  2685.           addword (0);
  2686.           addword (4);
  2687.         }
  2688.           break;
  2689.         default:
  2690.           as_fatal ("Internal error:  operand type B%c unknown in line %s of file \"%s\"",
  2691.             s[1], __LINE__, __FILE__);
  2692.         }
  2693.       break;
  2694.  
  2695.     case 'C':        /* Ignore it */
  2696.       break;
  2697.  
  2698.     case 'd':        /* JF this is a kludge */
  2699.       if (opP->mode == AOFF)
  2700.         {
  2701.           install_operand ('s', opP->reg - ADDR);
  2702.         }
  2703.       else
  2704.         {
  2705.           char *tmpP;
  2706.  
  2707.           tmpP = opP->con1->e_end - 2;
  2708.           opP->con1->e_beg++;
  2709.           opP->con1->e_end -= 4;    /* point to the , */
  2710.           baseo = m68k_reg_parse (&tmpP);
  2711.           if (baseo < ADDR + 0 || baseo > ADDR + 7)
  2712.         {
  2713.           as_bad ("Unknown address reg, using A0");
  2714.           baseo = 0;
  2715.         }
  2716.           else
  2717.         baseo -= ADDR;
  2718.           install_operand ('s', baseo);
  2719.         }
  2720.       tmpreg = get_num (opP->con1, 80);
  2721.       if (!issword (tmpreg))
  2722.         {
  2723.           as_warn ("Expression out of range, using 0");
  2724.           tmpreg = 0;
  2725.         }
  2726.       addword (tmpreg);
  2727.       break;
  2728.  
  2729.     case 'D':
  2730.       install_operand (s[1], opP->reg - DATA);
  2731.       break;
  2732.  
  2733.     case 'F':
  2734.       install_operand (s[1], opP->reg - FPREG);
  2735.       break;
  2736.  
  2737.     case 'I':
  2738.       tmpreg = 1 + opP->reg - COPNUM;
  2739.       if (tmpreg == 8)
  2740.         tmpreg = 0;
  2741.       install_operand (s[1], tmpreg);
  2742.       break;
  2743.  
  2744.     case 'J':        /* JF foo */
  2745.       switch (opP->reg)
  2746.         {
  2747.         case SFC:
  2748.           tmpreg = 0x000;
  2749.           break;
  2750.         case DFC:
  2751.           tmpreg = 0x001;
  2752.           break;
  2753.         case CACR:
  2754.           tmpreg = 0x002;
  2755.           break;
  2756.         case TC:
  2757.           tmpreg = 0x003;
  2758.           break;
  2759.         case ITT0:
  2760.           tmpreg = 0x004;
  2761.           break;
  2762.         case ITT1:
  2763.           tmpreg = 0x005;
  2764.           break;
  2765.         case DTT0:
  2766.           tmpreg = 0x006;
  2767.           break;
  2768.         case DTT1:
  2769.           tmpreg = 0x007;
  2770.           break;
  2771.  
  2772.         case USP:
  2773.           tmpreg = 0x800;
  2774.           break;
  2775.         case VBR:
  2776.           tmpreg = 0x801;
  2777.           break;
  2778.         case CAAR:
  2779.           tmpreg = 0x802;
  2780.           break;
  2781.         case MSP:
  2782.           tmpreg = 0x803;
  2783.           break;
  2784.         case ISP:
  2785.           tmpreg = 0x804;
  2786.           break;
  2787.         case MMUSR:
  2788.           tmpreg = 0x805;
  2789.           break;
  2790.         case URP:
  2791.           tmpreg = 0x806;
  2792.           break;
  2793.         case SRP:
  2794.           tmpreg = 0x807;
  2795.           break;
  2796.         default:
  2797.           as_fatal ("failed sanity check.");
  2798.         }
  2799.       install_operand (s[1], tmpreg);
  2800.       break;
  2801.  
  2802.     case 'k':
  2803.       tmpreg = get_num (opP->con1, 55);
  2804.       install_operand (s[1], tmpreg & 0x7f);
  2805.       break;
  2806.  
  2807.     case 'l':
  2808.       tmpreg = opP->reg;
  2809.       if (s[1] == 'w')
  2810.         {
  2811.           if (tmpreg & 0x7FF0000)
  2812.         as_bad ("Floating point register in register list");
  2813.           insop (reverse_16_bits (tmpreg));
  2814.         }
  2815.       else
  2816.         {
  2817.           if (tmpreg & 0x700FFFF)
  2818.         as_bad ("Wrong register in floating-point reglist");
  2819.           install_operand (s[1], reverse_8_bits (tmpreg >> 16));
  2820.         }
  2821.       break;
  2822.  
  2823.     case 'L':
  2824.       tmpreg = opP->reg;
  2825.       if (s[1] == 'w')
  2826.         {
  2827.           if (tmpreg & 0x7FF0000)
  2828.         as_bad ("Floating point register in register list");
  2829.           insop (tmpreg);
  2830.         }
  2831.       else if (s[1] == '8')
  2832.         {
  2833.           if (tmpreg & 0x0FFFFFF)
  2834.         as_bad ("incorrect register in reglist");
  2835.           install_operand (s[1], tmpreg >> 24);
  2836.         }
  2837.       else
  2838.         {
  2839.           if (tmpreg & 0x700FFFF)
  2840.         as_bad ("wrong register in floating-point reglist");
  2841.           else
  2842.         install_operand (s[1], tmpreg >> 16);
  2843.         }
  2844.       break;
  2845.  
  2846.     case 'M':
  2847.       install_operand (s[1], get_num (opP->con1, 60));
  2848.       break;
  2849.  
  2850.     case 'O':
  2851.       tmpreg = (opP->mode == DREG)
  2852.         ? 0x20 + opP->reg - DATA
  2853.         : (get_num (opP->con1, 40) & 0x1F);
  2854.       install_operand (s[1], tmpreg);
  2855.       break;
  2856.  
  2857.     case 'Q':
  2858.       tmpreg = get_num (opP->con1, 10);
  2859.       if (tmpreg == 8)
  2860.         tmpreg = 0;
  2861.       install_operand (s[1], tmpreg);
  2862.       break;
  2863.  
  2864.     case 'R':
  2865.     case 'r':
  2866.       /* This depends on the fact that ADDR registers are
  2867.      eight more than their corresponding DATA regs, so
  2868.      the result will have the ADDR_REG bit set */
  2869.       install_operand (s[1], opP->reg - DATA);
  2870.       break;
  2871.  
  2872.     case 's':
  2873.       if (opP->reg == FPI)
  2874.         tmpreg = 0x1;
  2875.       else if (opP->reg == FPS)
  2876.         tmpreg = 0x2;
  2877.       else if (opP->reg == FPC)
  2878.         tmpreg = 0x4;
  2879.       else
  2880.         as_fatal ("failed sanity check.");
  2881.       install_operand (s[1], tmpreg);
  2882.       break;
  2883.  
  2884.     case 'S':        /* Ignore it */
  2885.       break;
  2886.  
  2887.     case 'T':
  2888.       install_operand (s[1], get_num (opP->con1, 30));
  2889.       break;
  2890.  
  2891.     case 'U':        /* Ignore it */
  2892.       break;
  2893.  
  2894.     case 'c':
  2895.       switch (opP->reg)
  2896.         {
  2897.         case NC:
  2898.           tmpreg = 0;
  2899.           break;
  2900.         case DC:
  2901.           tmpreg = 1;
  2902.           break;
  2903.         case IC:
  2904.           tmpreg = 2;
  2905.           break;
  2906.         case BC:
  2907.           tmpreg = 3;
  2908.           break;
  2909.         default:
  2910.           as_fatal ("failed sanity check");
  2911.         }            /* switch on cache token */
  2912.       install_operand (s[1], tmpreg);
  2913.       break;
  2914. #ifndef NO_68851
  2915.       /* JF: These are out of order, I fear. */
  2916.     case 'f':
  2917.       switch (opP->reg)
  2918.         {
  2919.         case SFC:
  2920.           tmpreg = 0;
  2921.           break;
  2922.         case DFC:
  2923.           tmpreg = 1;
  2924.           break;
  2925.         default:
  2926.           as_fatal ("failed sanity check.");
  2927.         }
  2928.       install_operand (s[1], tmpreg);
  2929.       break;
  2930.  
  2931.     case 'P':
  2932.       switch (opP->reg)
  2933.         {
  2934.         case TC:
  2935.           tmpreg = 0;
  2936.           break;
  2937.         case CAL:
  2938.           tmpreg = 4;
  2939.           break;
  2940.         case VAL:
  2941.           tmpreg = 5;
  2942.           break;
  2943.         case SCC:
  2944.           tmpreg = 6;
  2945.           break;
  2946.         case AC:
  2947.           tmpreg = 7;
  2948.           break;
  2949.         default:
  2950.           as_fatal ("failed sanity check.");
  2951.         }
  2952.       install_operand (s[1], tmpreg);
  2953.       break;
  2954.  
  2955.     case 'V':
  2956.       if (opP->reg == VAL)
  2957.         break;
  2958.       as_fatal ("failed sanity check.");
  2959.  
  2960.     case 'W':
  2961.       switch (opP->reg)
  2962.         {
  2963.  
  2964.         case DRP:
  2965.           tmpreg = 1;
  2966.           break;
  2967.         case SRP:
  2968.           tmpreg = 2;
  2969.           break;
  2970.         case CRP:
  2971.           tmpreg = 3;
  2972.           break;
  2973.         default:
  2974.           as_fatal ("failed sanity check.");
  2975.         }
  2976.       install_operand (s[1], tmpreg);
  2977.       break;
  2978.  
  2979.     case 'X':
  2980.       switch (opP->reg)
  2981.         {
  2982.         case BAD:
  2983.         case BAD + 1:
  2984.         case BAD + 2:
  2985.         case BAD + 3:
  2986.         case BAD + 4:
  2987.         case BAD + 5:
  2988.         case BAD + 6:
  2989.         case BAD + 7:
  2990.           tmpreg = (4 << 10) | ((opP->reg - BAD) << 2);
  2991.           break;
  2992.  
  2993.         case BAC:
  2994.         case BAC + 1:
  2995.         case BAC + 2:
  2996.         case BAC + 3:
  2997.         case BAC + 4:
  2998.         case BAC + 5:
  2999.         case BAC + 6:
  3000.         case BAC + 7:
  3001.           tmpreg = (5 << 10) | ((opP->reg - BAC) << 2);
  3002.           break;
  3003.  
  3004.         default:
  3005.           as_fatal ("failed sanity check.");
  3006.         }
  3007.       install_operand (s[1], tmpreg);
  3008.       break;
  3009.     case 'Y':
  3010.       know (opP->reg == PSR);
  3011.       break;
  3012.     case 'Z':
  3013.       know (opP->reg == PCSR);
  3014.       break;
  3015. #endif /* m68851 */
  3016.     case '3':
  3017.       switch (opP->reg)
  3018.         {
  3019.         case TT0:
  3020.           tmpreg = 2;
  3021.           break;
  3022.         case TT1:
  3023.           tmpreg = 3;
  3024.           break;
  3025.         default:
  3026.           as_fatal ("failed sanity check");
  3027.         }
  3028.       install_operand (s[1], tmpreg);
  3029.       break;
  3030.     case 't':
  3031.       tmpreg = get_num (opP->con1, 20);
  3032.       install_operand (s[1], tmpreg);
  3033.       break;
  3034.     case '_':        /* used only for move16 absolute 32-bit address */
  3035.       tmpreg = get_num (opP->con1, 80);
  3036.       addword (tmpreg >> 16);
  3037.       addword (tmpreg & 0xFFFF);
  3038.       break;
  3039.     default:
  3040.       as_fatal ("Internal error:  Operand type %c unknown in line %d of file \"%s\"",
  3041.             s[0], __LINE__, __FILE__);
  3042.     }
  3043.     }
  3044.  
  3045.   /* By the time whe get here (FINALLY) the_ins contains the complete
  3046.      instruction, ready to be emitted. . . */
  3047. }                /* m68k_ip() */
  3048.  
  3049. /*
  3050.  * get_regs := '/' + ?
  3051.  *    | '-' + <register>
  3052.  *    | '-' + <register> + ?
  3053.  *    | <empty>
  3054.  *    ;
  3055.  *
  3056.  
  3057.  * The idea here must be to scan in a set of registers but I don't
  3058.  * understand it.  Looks awfully sloppy to me but I don't have any doc on
  3059.  * this format so...
  3060.  
  3061.  *
  3062.  *
  3063.  */
  3064.  
  3065. static int
  3066. get_regs (i, str, opP)
  3067.      int i;
  3068.      struct m68k_op *opP;
  3069.      char *str;
  3070. {
  3071.   /*                 26, 25, 24, 23-16,  15-8, 0-7 */
  3072.   /* Low order 24 bits encoded fpc,fps,fpi,fp7-fp0,a7-a0,d7-d0 */
  3073.   unsigned long cur_regs = 0;
  3074.   int reg1, reg2;
  3075.  
  3076. #define ADD_REG(x)    {     if(x==FPI) cur_regs|=(1<<24);\
  3077. else if(x==FPS) cur_regs|=(1<<25);\
  3078. else if(x==FPC) cur_regs|=(1<<26);\
  3079. else cur_regs|=(1<<(x-1));  }
  3080.  
  3081.   reg1 = i;
  3082.   for (;;)
  3083.     {
  3084.       if (*str == '/')
  3085.     {
  3086.       ADD_REG (reg1);
  3087.       str++;
  3088.     }
  3089.       else if (*str == '-')
  3090.     {
  3091.       str++;
  3092.       reg2 = m68k_reg_parse (&str);
  3093.       if (reg2 < DATA || reg2 >= FPREG + 8 || reg1 == FPI || reg1 == FPS || reg1 == FPC)
  3094.         {
  3095.           opP->error = "unknown register in register list";
  3096.           return FAIL;
  3097.         }
  3098.       while (reg1 <= reg2)
  3099.         {
  3100.           ADD_REG (reg1);
  3101.           reg1++;
  3102.         }
  3103.       if (*str == '\0')
  3104.         break;
  3105.     }
  3106.       else if (*str == '\0')
  3107.     {
  3108.       ADD_REG (reg1);
  3109.       break;
  3110.     }
  3111.       else
  3112.     {
  3113.       opP->error = "unknow character in register list";
  3114.       return FAIL;
  3115.     }
  3116.       /* DJA -- Bug Fix.  Did't handle d1-d2/a1 until the following instruction was added */
  3117.       if (*str == '/')
  3118.     str++;
  3119.       reg1 = m68k_reg_parse (&str);
  3120.       if ((reg1 < DATA || reg1 >= FPREG + 8) && !(reg1 == FPI || reg1 == FPS || reg1 == FPC))
  3121.     {
  3122.       opP->error = "unknown register in register list";
  3123.       return FAIL;
  3124.     }
  3125.     }
  3126.   opP->reg = cur_regs;
  3127.   return OK;
  3128. }                /* get_regs() */
  3129.  
  3130. static int
  3131. reverse_16_bits (in)
  3132.      int in;
  3133. {
  3134.   int out = 0;
  3135.   int n;
  3136.  
  3137.   static int mask[16] =
  3138.   {
  3139.     0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
  3140.     0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000, 0x8000
  3141.   };
  3142.   for (n = 0; n < 16; n++)
  3143.     {
  3144.       if (in & mask[n])
  3145.     out |= mask[15 - n];
  3146.     }
  3147.   return out;
  3148. }                /* reverse_16_bits() */
  3149.  
  3150. static int
  3151. reverse_8_bits (in)
  3152.      int in;
  3153. {
  3154.   int out = 0;
  3155.   int n;
  3156.  
  3157.   static int mask[8] =
  3158.   {
  3159.     0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
  3160.   };
  3161.  
  3162.   for (n = 0; n < 8; n++)
  3163.     {
  3164.       if (in & mask[n])
  3165.     out |= mask[7 - n];
  3166.     }
  3167.   return out;
  3168. }                /* reverse_8_bits() */
  3169.  
  3170. static void
  3171. install_operand (mode, val)
  3172.      int mode;
  3173.      int val;
  3174. {
  3175.   switch (mode)
  3176.     {
  3177.     case 's':
  3178.       the_ins.opcode[0] |= val & 0xFF;    /* JF FF is for M kludge */
  3179.       break;
  3180.     case 'd':
  3181.       the_ins.opcode[0] |= val << 9;
  3182.       break;
  3183.     case '1':
  3184.       the_ins.opcode[1] |= val << 12;
  3185.       break;
  3186.     case '2':
  3187.       the_ins.opcode[1] |= val << 6;
  3188.       break;
  3189.     case '3':
  3190.       the_ins.opcode[1] |= val;
  3191.       break;
  3192.     case '4':
  3193.       the_ins.opcode[2] |= val << 12;
  3194.       break;
  3195.     case '5':
  3196.       the_ins.opcode[2] |= val << 6;
  3197.       break;
  3198.     case '6':
  3199.       /* DANGER!  This is a hack to force cas2l and cas2w cmds
  3200.            to be three words long! */
  3201.       the_ins.numo++;
  3202.       the_ins.opcode[2] |= val;
  3203.       break;
  3204.     case '7':
  3205.       the_ins.opcode[1] |= val << 7;
  3206.       break;
  3207.     case '8':
  3208.       the_ins.opcode[1] |= val << 10;
  3209.       break;
  3210. #ifndef NO_68851
  3211.     case '9':
  3212.       the_ins.opcode[1] |= val << 5;
  3213.       break;
  3214. #endif
  3215.  
  3216.     case 't':
  3217.       the_ins.opcode[1] |= (val << 10) | (val << 7);
  3218.       break;
  3219.     case 'D':
  3220.       the_ins.opcode[1] |= (val << 12) | val;
  3221.       break;
  3222.     case 'g':
  3223.       the_ins.opcode[0] |= val = 0xff;
  3224.       break;
  3225.     case 'i':
  3226.       the_ins.opcode[0] |= val << 9;
  3227.       break;
  3228.     case 'C':
  3229.       the_ins.opcode[1] |= val;
  3230.       break;
  3231.     case 'j':
  3232.       the_ins.opcode[1] |= val;
  3233.       the_ins.numo++;        /* What a hack */
  3234.       break;
  3235.     case 'k':
  3236.       the_ins.opcode[1] |= val << 4;
  3237.       break;
  3238.     case 'b':
  3239.     case 'w':
  3240.     case 'l':
  3241.       break;
  3242.     case 'e':
  3243.       the_ins.opcode[0] |= (val << 6);
  3244.       break;
  3245.     case 'L':
  3246.       the_ins.opcode[1] = (val >> 16);
  3247.       the_ins.opcode[2] = val & 0xffff;
  3248.       break;
  3249.     case 'c':
  3250.     default:
  3251.       as_fatal ("failed sanity check.");
  3252.     }
  3253. }                /* install_operand() */
  3254.  
  3255. static void
  3256. install_gen_operand (mode, val)
  3257.      int mode;
  3258.      int val;
  3259. {
  3260.   switch (mode)
  3261.     {
  3262.     case 's':
  3263.       the_ins.opcode[0] |= val;
  3264.       break;
  3265.     case 'd':
  3266.       /* This is a kludge!!! */
  3267.       the_ins.opcode[0] |= (val & 0x07) << 9 | (val & 0x38) << 3;
  3268.       break;
  3269.     case 'b':
  3270.     case 'w':
  3271.     case 'l':
  3272.     case 'f':
  3273.     case 'F':
  3274.     case 'x':
  3275.     case 'p':
  3276.       the_ins.opcode[0] |= val;
  3277.       break;
  3278.       /* more stuff goes here */
  3279.     default:
  3280.       as_fatal ("failed sanity check.");
  3281.     }
  3282. }                /* install_gen_operand() */
  3283.  
  3284. /*
  3285.  * verify that we have some number of paren pairs, do m68k_ip_op(), and
  3286.  * then deal with the bitfield hack.
  3287.  */
  3288.  
  3289. static char *
  3290. crack_operand (str, opP)
  3291.      register char *str;
  3292.      register struct m68k_op *opP;
  3293. {
  3294.   register int parens;
  3295.   register int c;
  3296.   register char *beg_str;
  3297.  
  3298.   if (!str)
  3299.     {
  3300.       return str;
  3301.     }
  3302.   beg_str = str;
  3303.   for (parens = 0; *str && (parens > 0 || notend (str)); str++)
  3304.     {
  3305.       if (*str == '(')
  3306.     parens++;
  3307.       else if (*str == ')')
  3308.     {
  3309.       if (!parens)
  3310.         {            /* ERROR */
  3311.           opP->error = "Extra )";
  3312.           return str;
  3313.         }
  3314.       --parens;
  3315.     }
  3316.     }
  3317.   if (!*str && parens)
  3318.     {                /* ERROR */
  3319.       opP->error = "Missing )";
  3320.       return str;
  3321.     }
  3322.   c = *str;
  3323.   *str = '\0';
  3324.   if (m68k_ip_op (beg_str, opP) == FAIL)
  3325.     {
  3326.       *str = c;
  3327.       return str;
  3328.     }
  3329.   *str = c;
  3330.   if (c == '}')
  3331.     c = *++str;            /* JF bitfield hack */
  3332.   if (c)
  3333.     {
  3334.       c = *++str;
  3335.       if (!c)
  3336.     as_bad ("Missing operand");
  3337.     }
  3338.   return str;
  3339. }
  3340.  
  3341. /* See the comment up above where the #define notend(... is */
  3342. #if 0
  3343. notend (s)
  3344.      char *s;
  3345. {
  3346.   if (*s == ',')
  3347.     return 0;
  3348.   if (*s == '{' || *s == '}')
  3349.     return 0;
  3350.   if (*s != ':')
  3351.     return 1;
  3352.   /* This kludge here is for the division cmd, which is a kludge */
  3353.   if (index ("aAdD#", s[1]))
  3354.     return 0;
  3355.   return 1;
  3356. }
  3357.  
  3358. #endif
  3359.  
  3360. /* This is the guts of the machine-dependent assembler.  STR points to a
  3361.    machine dependent instruction.  This function is supposed to emit
  3362.    the frags/bytes it assembles to.
  3363.    */
  3364.  
  3365. void
  3366. insert_reg (regname, regnum)
  3367.      char *regname;
  3368.      int regnum;
  3369. {
  3370.   char buf[100];
  3371.   int i;
  3372. symbolS *s;
  3373.  
  3374. #ifdef REGISTER_PREFIX
  3375.   buf[0] = REGISTER_PREFIX;
  3376.   strcpy (buf + 1, regname);
  3377.   regname = buf;
  3378. #endif
  3379.  
  3380.   symbol_table_insert (s = symbol_new (regname, reg_section, regnum, &zero_address_frag));
  3381.  
  3382. verify_symbol_chain_2 (s);
  3383.  
  3384.   for (i = 0; regname[i]; i++)
  3385.     buf[i] = islower (regname[i]) ? toupper (regname[i]) : regname[i];
  3386.   buf[i] = '\0';
  3387.  
  3388.   symbol_table_insert (s = symbol_new (buf, reg_section, regnum, &zero_address_frag));
  3389. verify_symbol_chain_2 (s);
  3390. }
  3391.  
  3392. struct init_entry
  3393.   {
  3394.     char *name;
  3395.     int number;
  3396.   };
  3397.  
  3398. static CONST struct init_entry init_table[] =
  3399. {
  3400.   "d0", DATA0,
  3401.   "d1", DATA1,
  3402.   "d2", DATA2,
  3403.   "d3", DATA3,
  3404.   "d4", DATA4,
  3405.   "d5", DATA5,
  3406.   "d6", DATA6,
  3407.   "d7", DATA7,
  3408.   "a0", ADDR0,
  3409.   "a1", ADDR1,
  3410.   "a2", ADDR2,
  3411.   "a3", ADDR3,
  3412.   "a4", ADDR4,
  3413.   "a5", ADDR5,
  3414.   "a6", ADDR6,
  3415.   "fp", ADDR6,
  3416.   "a7", ADDR7,
  3417.   "sp", ADDR7,
  3418.   "fp0", FP0,
  3419.   "fp1", FP1,
  3420.   "fp2", FP2,
  3421.   "fp3", FP3,
  3422.   "fp4", FP4,
  3423.   "fp5", FP5,
  3424.   "fp6", FP6,
  3425.   "fp7", FP7,
  3426.   "fpi", FPI,
  3427.   "fpiar", FPI,
  3428.   "fpc", FPI,
  3429.   "fps", FPS,
  3430.   "fpsr", FPS,
  3431.   "fpc", FPC,
  3432.   "fpcr", FPC,
  3433.  
  3434.   "cop0", COP0,
  3435.   "cop1", COP1,
  3436.   "cop2", COP2,
  3437.   "cop3", COP3,
  3438.   "cop4", COP4,
  3439.   "cop5", COP5,
  3440.   "cop6", COP6,
  3441.   "cop7", COP7,
  3442.   "pc", PC,
  3443.   "zpc", ZPC,
  3444.   "sr", SR,
  3445.  
  3446.   "ccr", CCR,
  3447.   "cc", CCR,
  3448.  
  3449.   "usp", USP,
  3450.   "isp", ISP,
  3451.   "sfc", SFC,
  3452.   "dfc", DFC,
  3453.   "cacr", CACR,
  3454.   "caar", CAAR,
  3455.  
  3456.   "vbr", VBR,
  3457.  
  3458.   "msp", MSP,
  3459.   "itt0", ITT0,
  3460.   "itt1", ITT1,
  3461.   "dtt0", DTT0,
  3462.   "dtt1", DTT1,
  3463.   "mmusr", MMUSR,
  3464.   "tc", TC,
  3465.   "srp", SRP,
  3466.   "urp", URP,
  3467.  
  3468.   "ac", AC,
  3469.   "bc", BC,
  3470.   "cal", CAL,
  3471.   "crp", CRP,
  3472.   "drp", DRP,
  3473.   "pcsr", PCSR,
  3474.   "psr", PSR,
  3475.   "scc", SCC,
  3476.   "val", VAL,
  3477.   "bad0", BAD0,
  3478.   "bad1", BAD1,
  3479.   "bad2", BAD2,
  3480.   "bad3", BAD3,
  3481.   "bad4", BAD4,
  3482.   "bad5", BAD5,
  3483.   "bad6", BAD6,
  3484.   "bad7", BAD7,
  3485.   "bac0", BAC0,
  3486.   "bac1", BAC1,
  3487.   "bac2", BAC2,
  3488.   "bac3", BAC3,
  3489.   "bac4", BAC4,
  3490.   "bac5", BAC5,
  3491.   "bac6", BAC6,
  3492.   "bac7", BAC7,
  3493.  
  3494.   "ic", IC,
  3495.   "dc", DC,
  3496.   "nc", NC,
  3497.  
  3498.   "tt0", TT0,
  3499.   "tt1", TT1,
  3500.   /* 68ec030 versions of same */
  3501.   "ac0", TT0,
  3502.   "ac1", TT1,
  3503.   /* 68ec030 access control unit, identical to 030 MMU status reg */
  3504.   "acusr", PSR,
  3505.  
  3506.   0,
  3507.  
  3508. };
  3509.  
  3510.  
  3511. void
  3512. init_regtable ()
  3513. {
  3514.   int i;
  3515.   for (i = 0; init_table[i].name; i++)
  3516.     insert_reg (init_table[i].name, init_table[i].number);
  3517. }
  3518.  
  3519. static int no_68851, no_68881;
  3520.  
  3521. void
  3522. md_assemble (str)
  3523.      char *str;
  3524. {
  3525.   char *er;
  3526.   short *fromP;
  3527.   char *toP = NULL;
  3528.   int m, n = 0;
  3529.   char *to_beg_P;
  3530.   int shorts_this_frag;
  3531.   static int done_first_time;
  3532.  
  3533.   if (!done_first_time)
  3534.     {
  3535.       done_first_time = 1;
  3536.  
  3537.       if (cpu_of_arch (current_architecture) == 0)
  3538.     {
  3539.       int cpu_type;
  3540.  
  3541.       if (strcmp (TARGET_CPU, "m68000") == 0
  3542.           || strcmp (TARGET_CPU, "m68302") == 0)
  3543.         cpu_type = m68000;
  3544.       else if (strcmp (TARGET_CPU, "m68010") == 0)
  3545.         cpu_type = m68010;
  3546.       else if (strcmp (TARGET_CPU, "m68020") == 0
  3547.            || strcmp (TARGET_CPU, "m68k") == 0)
  3548.         cpu_type = m68020;
  3549.       else if (strcmp (TARGET_CPU, "m68030") == 0)
  3550.         cpu_type = m68030;
  3551.       else if (strcmp (TARGET_CPU, "m68040") == 0)
  3552.         cpu_type = m68040;
  3553.       else if (strcmp (TARGET_CPU, "cpu32") == 0
  3554.            || strcmp (TARGET_CPU, "m68331") == 0
  3555.            || strcmp (TARGET_CPU, "m68332") == 0
  3556.            || strcmp (TARGET_CPU, "m68333") == 0
  3557.            || strcmp (TARGET_CPU, "m68340") == 0)
  3558.         cpu_type = cpu32;
  3559.       else
  3560.         cpu_type = m68020;
  3561.  
  3562.       current_architecture |= cpu_type;
  3563.     }
  3564. #if 0                /* Could be doing emulation.  */
  3565.       if (current_architecture & m68881)
  3566.     {
  3567.       if (current_architecture & m68000)
  3568.         as_bad ("incompatible processors 68000 and 68881/2 specified");
  3569.       if (current_architecture & m68010)
  3570.         as_bad ("incompatible processors 68010 and 68881/2 specified");
  3571.       if (current_architecture & m68040)
  3572.         as_bad ("incompatible processors 68040 and 68881/2 specified");
  3573.     }
  3574. #endif
  3575.       /* What other incompatibilities could we check for?  */
  3576.  
  3577.       /* Toss in some default assumptions about coprocessors.  */
  3578.       if (!no_68881
  3579.       && (cpu_of_arch (current_architecture)
  3580.       /* Can CPU32 have a 68881 coprocessor??  */
  3581.           & (m68020 | m68030 | cpu32)))
  3582.     {
  3583.       current_architecture |= m68881;
  3584.     }
  3585.       if (!no_68851
  3586.       && (cpu_of_arch (current_architecture) & m68020up) != 0)
  3587.     {
  3588.       current_architecture |= m68851;
  3589.     }
  3590.       if (no_68881 && (current_architecture & m68881))
  3591.     as_bad ("options for 68881 and no-68881 both given");
  3592.       if (no_68851 && (current_architecture & m68851))
  3593.     as_bad ("options for 68851 and no-68851 both given");
  3594.       done_first_time = 1;
  3595.     }
  3596.  
  3597.   memset ((char *) (&the_ins), '\0', sizeof (the_ins));
  3598.   m68k_ip (str);
  3599.   er = the_ins.error;
  3600.   if (!er)
  3601.     {
  3602.       for (n = the_ins.numargs; n; --n)
  3603.     if (the_ins.operands[n].error)
  3604.       {
  3605.         er = the_ins.operands[n].error;
  3606.         break;
  3607.       }
  3608.     }
  3609.   if (er)
  3610.     {
  3611.       as_bad ("%s -- statement `%s' ignored", er, str);
  3612.       return;
  3613.     }
  3614.  
  3615.   if (the_ins.nfrag == 0)
  3616.     {
  3617.       /* No frag hacking involved; just put it out */
  3618.       toP = frag_more (2 * the_ins.numo);
  3619.       fromP = &the_ins.opcode[0];
  3620.       for (m = the_ins.numo; m; --m)
  3621.     {
  3622.       md_number_to_chars (toP, (long) (*fromP), 2);
  3623.       toP += 2;
  3624.       fromP++;
  3625.     }
  3626.       /* put out symbol-dependent info */
  3627.       for (m = 0; m < the_ins.nrel; m++)
  3628.     {
  3629.       switch (the_ins.reloc[m].wid)
  3630.         {
  3631.         case 'B':
  3632.           n = 1;
  3633.           break;
  3634.         case 'b':
  3635.           n = 1;
  3636.           break;
  3637.         case '3':
  3638.           n = 2;
  3639.           break;
  3640.         case 'w':
  3641.           n = 2;
  3642.           break;
  3643.         case 'l':
  3644.           n = 4;
  3645.           break;
  3646.         default:
  3647.           as_fatal ("Don't know how to figure width of %c in md_assemble()",
  3648.             the_ins.reloc[m].wid);
  3649.         }
  3650.  
  3651.       fix_new (frag_now,
  3652.            (toP - frag_now->fr_literal) - the_ins.numo * 2 + the_ins.reloc[m].n,
  3653.            n,
  3654.            the_ins.reloc[m].add,
  3655.            the_ins.reloc[m].sub,
  3656.            the_ins.reloc[m].off,
  3657.            the_ins.reloc[m].pcrel,
  3658.            NO_RELOC);
  3659.     }
  3660.       return;
  3661.     }
  3662.  
  3663.   /* There's some frag hacking */
  3664.   for (n = 0, fromP = &the_ins.opcode[0]; n < the_ins.nfrag; n++)
  3665.     {
  3666.       int wid;
  3667.  
  3668.       if (n == 0)
  3669.     wid = 2 * the_ins.fragb[n].fragoff;
  3670.       else
  3671.     wid = 2 * (the_ins.numo - the_ins.fragb[n - 1].fragoff);
  3672.       toP = frag_more (wid);
  3673.       to_beg_P = toP;
  3674.       shorts_this_frag = 0;
  3675.       for (m = wid / 2; m; --m)
  3676.     {
  3677.       md_number_to_chars (toP, (long) (*fromP), 2);
  3678.       toP += 2;
  3679.       fromP++;
  3680.       shorts_this_frag++;
  3681.     }
  3682.       for (m = 0; m < the_ins.nrel; m++)
  3683.     {
  3684.       if ((the_ins.reloc[m].n) >= 2 * shorts_this_frag)
  3685.         {
  3686.           the_ins.reloc[m].n -= 2 * shorts_this_frag;
  3687.           break;
  3688.         }
  3689.       wid = the_ins.reloc[m].wid;
  3690.       if (wid == 0)
  3691.         continue;
  3692.       the_ins.reloc[m].wid = 0;
  3693.       wid = (wid == 'b') ? 1 : (wid == 'w') ? 2 : (wid == 'l') ? 4 : 4000;
  3694.  
  3695.       fix_new (frag_now,
  3696.            (toP - frag_now->fr_literal) - the_ins.numo * 2 + the_ins.reloc[m].n,
  3697.            wid,
  3698.            the_ins.reloc[m].add,
  3699.            the_ins.reloc[m].sub,
  3700.            the_ins.reloc[m].off,
  3701.            the_ins.reloc[m].pcrel,
  3702.            NO_RELOC);
  3703.     }
  3704.       (void) frag_var (rs_machine_dependent, 10, 0,
  3705.                (relax_substateT) (the_ins.fragb[n].fragty),
  3706.                the_ins.fragb[n].fadd, the_ins.fragb[n].foff, to_beg_P);
  3707.     }
  3708.   n = (the_ins.numo - the_ins.fragb[n - 1].fragoff);
  3709.   shorts_this_frag = 0;
  3710.   if (n)
  3711.     {
  3712.       toP = frag_more (n * sizeof (short));
  3713.       while (n--)
  3714.     {
  3715.       md_number_to_chars (toP, (long) (*fromP), 2);
  3716.       toP += 2;
  3717.       fromP++;
  3718.       shorts_this_frag++;
  3719.     }
  3720.     }
  3721.   for (m = 0; m < the_ins.nrel; m++)
  3722.     {
  3723.       int wid;
  3724.  
  3725.       wid = the_ins.reloc[m].wid;
  3726.       if (wid == 0)
  3727.     continue;
  3728.       the_ins.reloc[m].wid = 0;
  3729.       wid = (wid == 'b') ? 1 : (wid == 'w') ? 2 : (wid == 'l') ? 4 : 4000;
  3730.  
  3731.       fix_new (frag_now,
  3732.            (the_ins.reloc[m].n + toP - frag_now->fr_literal) - shorts_this_frag * 2,
  3733.            wid,
  3734.            the_ins.reloc[m].add,
  3735.            the_ins.reloc[m].sub,
  3736.            the_ins.reloc[m].off,
  3737.            the_ins.reloc[m].pcrel,
  3738.            NO_RELOC);
  3739.     }
  3740. }
  3741.  
  3742. /* See BREAK_UP_BIG_DECL definition, above.  */
  3743. static struct m68k_opcode *
  3744. opcode_ptr (i)
  3745.      int i;
  3746. {
  3747. #ifdef DO_BREAK_UP_BIG_DECL
  3748.   int lim1 = sizeof (m68k_opcodes) / sizeof (m68k_opcodes[0]);
  3749.   if (i >= lim1)
  3750.     return m68k_opcodes_2 + (i - lim1);
  3751. #endif
  3752.   return m68k_opcodes + i;
  3753. }
  3754.  
  3755. void
  3756. md_begin ()
  3757. {
  3758.   /*
  3759.    * md_begin -- set up hash tables with 68000 instructions.
  3760.    * similar to what the vax assembler does.  ---phr
  3761.    */
  3762.   /* RMS claims the thing to do is take the m68k-opcode.h table, and make
  3763.      a copy of it at runtime, adding in the information we want but isn't
  3764.      there.  I think it'd be better to have an awk script hack the table
  3765.      at compile time.  Or even just xstr the table and use it as-is.  But
  3766.      my lord ghod hath spoken, so we do it this way.  Excuse the ugly var
  3767.      names.  */
  3768.  
  3769.   register CONST struct m68k_opcode *ins;
  3770.   register struct m68k_incant *hack, *slak;
  3771.   register char *retval = 0;    /* empty string, or error msg text */
  3772.   register unsigned int i;
  3773.   register char c;
  3774.  
  3775.   if ((op_hash = hash_new ()) == NULL)
  3776.     as_fatal ("Virtual memory exhausted");
  3777.  
  3778.   obstack_begin (&robyn, 4000);
  3779.   for (i = 0; i < numopcodes; i++)
  3780.     {
  3781.       hack = slak = (struct m68k_incant *) obstack_alloc (&robyn, sizeof (struct m68k_incant));
  3782.       do
  3783.     {
  3784.       ins = opcode_ptr (i);
  3785.       /* We *could* ignore insns that don't match our arch here
  3786.          but just leaving them out of the hash. */
  3787.       slak->m_operands = ins->args;
  3788.       slak->m_opnum = strlen (slak->m_operands) / 2;
  3789.       slak->m_arch = ins->arch;
  3790.       slak->m_opcode = ins->opcode;
  3791.       /* This is kludgey */
  3792.       slak->m_codenum = ((ins->match) & 0xffffL) ? 2 : 1;
  3793.       if (i + 1 != numopcodes
  3794.           && !strcmp (ins->name, opcode_ptr (i + 1)->name))
  3795.         {
  3796.           slak->m_next = (struct m68k_incant *) obstack_alloc (&robyn, sizeof (struct m68k_incant));
  3797.           i++;
  3798.         }
  3799.       else
  3800.         slak->m_next = 0;
  3801.       slak = slak->m_next;
  3802.     }
  3803.       while (slak);
  3804.  
  3805.       retval = hash_insert (op_hash, ins->name, (char *) hack);
  3806.       /* Didn't his mommy tell him about null pointers? */
  3807.       if (retval && *retval)
  3808.     as_bad ("Internal Error:  Can't hash %s: %s", ins->name, retval);
  3809.     }
  3810.  
  3811.   for (i = 0; i < sizeof (mklower_table); i++)
  3812.     mklower_table[i] = (isupper (c = (char) i)) ? tolower (c) : c;
  3813.  
  3814.   for (i = 0; i < sizeof (notend_table); i++)
  3815.     {
  3816.       notend_table[i] = 0;
  3817.       alt_notend_table[i] = 0;
  3818.     }
  3819.   notend_table[','] = 1;
  3820.   notend_table['{'] = 1;
  3821.   notend_table['}'] = 1;
  3822.   alt_notend_table['a'] = 1;
  3823.   alt_notend_table['A'] = 1;
  3824.   alt_notend_table['d'] = 1;
  3825.   alt_notend_table['D'] = 1;
  3826.   alt_notend_table['#'] = 1;
  3827.   alt_notend_table['f'] = 1;
  3828.   alt_notend_table['F'] = 1;
  3829. #ifdef REGISTER_PREFIX
  3830.   alt_notend_table[REGISTER_PREFIX] = 1;
  3831. #endif
  3832. #ifdef OPTIONAL_REGISTER_PREFIX
  3833.   alt_notend_table[OPTIONAL_REGISTER_PREFIX] = 1;
  3834. #endif
  3835.  
  3836. #ifndef MIT_SYNTAX_ONLY
  3837.   /* Insert pseudo ops, these have to go into the opcode table since
  3838.        gas expects pseudo ops to start with a dot */
  3839.   {
  3840.     int n = 0;
  3841.     while (mote_pseudo_table[n].poc_name)
  3842.       {
  3843.     hack = (struct m68k_incant *)
  3844.       obstack_alloc (&robyn, sizeof (struct m68k_incant));
  3845.     hash_insert (op_hash,
  3846.              mote_pseudo_table[n].poc_name, (char *) hack);
  3847.     hack->m_operands = 0;
  3848.     hack->m_opnum = n;
  3849.     n++;
  3850.       }
  3851.   }
  3852. #endif
  3853.  
  3854.   init_regtable ();
  3855. }
  3856.  
  3857. #if 0
  3858. #define notend(s) ((*s == ',' || *s == '}' || *s == '{' \
  3859.             || (*s == ':' && strchr("aAdD#", s[1]))) \
  3860.            ? 0 : 1)
  3861. #endif
  3862.  
  3863. /* This funciton is called once, before the assembler exits.  It is
  3864.    supposed to do any final cleanup for this part of the assembler.
  3865.    */
  3866. void
  3867. md_end ()
  3868. {
  3869. }
  3870.  
  3871. /* Equal to MAX_PRECISION in atof-ieee.c */
  3872. #define MAX_LITTLENUMS 6
  3873.  
  3874. /* Turn a string in input_line_pointer into a floating point constant of type
  3875.    type, and store the appropriate bytes in *litP.  The number of LITTLENUMS
  3876.    emitted is stored in *sizeP .  An error message is returned, or NULL on OK.
  3877.    */
  3878. char *
  3879. md_atof (type, litP, sizeP)
  3880.      char type;
  3881.      char *litP;
  3882.      int *sizeP;
  3883. {
  3884.   int prec;
  3885.   LITTLENUM_TYPE words[MAX_LITTLENUMS];
  3886.   LITTLENUM_TYPE *wordP;
  3887.   char *t;
  3888.   char *atof_ieee ();
  3889.  
  3890.   switch (type)
  3891.     {
  3892.     case 'f':
  3893.     case 'F':
  3894.     case 's':
  3895.     case 'S':
  3896.       prec = 2;
  3897.       break;
  3898.  
  3899.     case 'd':
  3900.     case 'D':
  3901.     case 'r':
  3902.     case 'R':
  3903.       prec = 4;
  3904.       break;
  3905.  
  3906.     case 'x':
  3907.     case 'X':
  3908.       prec = 6;
  3909.       break;
  3910.  
  3911.     case 'p':
  3912.     case 'P':
  3913.       prec = 6;
  3914.       break;
  3915.  
  3916.     default:
  3917.       *sizeP = 0;
  3918.       return "Bad call to MD_ATOF()";
  3919.     }
  3920.   t = atof_ieee (input_line_pointer, type, words);
  3921.   if (t)
  3922.     input_line_pointer = t;
  3923.  
  3924.   *sizeP = prec * sizeof (LITTLENUM_TYPE);
  3925.   for (wordP = words; prec--;)
  3926.     {
  3927.       md_number_to_chars (litP, (long) (*wordP++), sizeof (LITTLENUM_TYPE));
  3928.       litP += sizeof (LITTLENUM_TYPE);
  3929.     }
  3930.   return 0;
  3931. }
  3932.  
  3933. /* Turn an integer of n bytes (in val) into a stream of bytes appropriate
  3934.    for use in the a.out file, and stores them in the array pointed to by buf.
  3935.    This knows about the endian-ness of the target machine and does
  3936.    THE RIGHT THING, whatever it is.  Possible values for n are 1 (byte)
  3937.    2 (short) and 4 (long)  Floating numbers are put out as a series of
  3938.    LITTLENUMS (shorts, here at least)
  3939.    */
  3940. void
  3941. md_number_to_chars (buf, val, n)
  3942.      char *buf;
  3943.      long val;
  3944.      int n;
  3945. {
  3946.   switch (n)
  3947.     {
  3948.     case 1:
  3949.       *buf++ = val;
  3950.       break;
  3951.     case 2:
  3952.       *buf++ = (val >> 8);
  3953.       *buf++ = val;
  3954.       break;
  3955.     case 4:
  3956.       *buf++ = (val >> 24);
  3957.       *buf++ = (val >> 16);
  3958.       *buf++ = (val >> 8);
  3959.       *buf++ = val;
  3960.       break;
  3961.     default:
  3962.       as_fatal ("failed sanity check.");
  3963.     }
  3964. }
  3965.  
  3966. static void
  3967. md_apply_fix_2 (fixP, val)
  3968.      fixS *fixP;
  3969.      long val;
  3970. {
  3971.   unsigned long upper_limit;
  3972.   long lower_limit;
  3973.  
  3974. #ifdef IBM_COMPILER_SUX
  3975.   /* This is unnecessary but it convinces the native rs6000
  3976.      compiler to generate the code we want. */
  3977.   char *buf = fixP->fx_frag->fr_literal;
  3978.   buf += fixP->fx_where;
  3979. #else /* IBM_COMPILER_SUX */
  3980.   char *buf = fixP->fx_where + fixP->fx_frag->fr_literal;
  3981. #endif /* IBM_COMPILER_SUX */
  3982.  
  3983.   switch (fixP->fx_size)
  3984.     {
  3985.     case 1:
  3986.       *buf++ = val;
  3987.       upper_limit = 0x7f;
  3988.       lower_limit = -0x80;
  3989.       break;
  3990.     case 2:
  3991.       *buf++ = (val >> 8);
  3992.       *buf++ = val;
  3993.       upper_limit = 0x7fff;
  3994.       lower_limit = -0x8000;
  3995.       break;
  3996.     case 4:
  3997.       *buf++ = (val >> 24);
  3998.       *buf++ = (val >> 16);
  3999.       *buf++ = (val >> 8);
  4000.       *buf++ = val;
  4001.       upper_limit = 0x7fffffff;
  4002.       lower_limit = -0x80000000;
  4003.       break;
  4004.     default:
  4005.       BAD_CASE (fixP->fx_size);
  4006.     }
  4007.  
  4008.   /* For non-pc-relative values, it's conceivable we might get something
  4009.      like "0xff" for a byte field.  So extend the upper part of the range
  4010.      to accept such numbers.  We arbitrarily disallow "-0xff" or "0xff+0xff",
  4011.      so that we can do any range checking at all.  */
  4012.   if (!fixP->fx_pcrel)
  4013.     upper_limit = upper_limit * 2 + 1;
  4014.  
  4015.   if ((unsigned) val > upper_limit && (val > 0 || val < lower_limit))
  4016.     as_bad ("value out of range");
  4017. }
  4018.  
  4019. #ifdef BFD_ASSEMBLER
  4020. int
  4021. md_apply_fix (fixP, valp)
  4022.      fixS *fixP;
  4023.      long *valp;
  4024. {
  4025.   md_apply_fix_2 (fixP, *valp);
  4026.   return 1;
  4027. }
  4028. #else
  4029. void md_apply_fix (fixP, val)
  4030.      fixS *fixP;
  4031.      long val;
  4032. {
  4033.   md_apply_fix_2 (fixP, val);
  4034. }
  4035. #endif
  4036.  
  4037. /* *fragP has been relaxed to its final size, and now needs to have
  4038.    the bytes inside it modified to conform to the new size  There is UGLY
  4039.    MAGIC here. ..
  4040.    */
  4041. void
  4042. md_convert_frag_1 (fragP)
  4043.      register fragS *fragP;
  4044. {
  4045.   long disp;
  4046.   long ext = 0;
  4047.  
  4048.   /* Address in object code of the displacement.  */
  4049.   register int object_address = fragP->fr_fix + fragP->fr_address;
  4050.  
  4051. #ifdef IBM_COMPILER_SUX
  4052.   /* This is wrong but it convinces the native rs6000 compiler to
  4053.      generate the code we want. */
  4054.   register char *buffer_address = fragP->fr_literal;
  4055.   buffer_address += fragP->fr_fix;
  4056. #else /* IBM_COMPILER_SUX */
  4057.   /* Address in gas core of the place to store the displacement.  */
  4058.   register char *buffer_address = fragP->fr_fix + fragP->fr_literal;
  4059. #endif /* IBM_COMPILER_SUX */
  4060.  
  4061.   /* No longer true:   know(fragP->fr_symbol); */
  4062.  
  4063.   /* The displacement of the address, from current location.  */
  4064.   disp = fragP->fr_symbol ? S_GET_VALUE (fragP->fr_symbol) : 0;
  4065.   disp = (disp + fragP->fr_offset) - object_address;
  4066.  
  4067.   switch (fragP->fr_subtype)
  4068.     {
  4069.     case TAB (BCC68000, BYTE):
  4070.     case TAB (ABRANCH, BYTE):
  4071.       know (issbyte (disp));
  4072.       if (disp == 0)
  4073.     as_bad ("short branch with zero offset: use :w");
  4074.       fragP->fr_opcode[1] = disp;
  4075.       ext = 0;
  4076.       break;
  4077.     case TAB (DBCC, SHORT):
  4078.       know (issword (disp));
  4079.       ext = 2;
  4080.       break;
  4081.     case TAB (BCC68000, SHORT):
  4082.     case TAB (ABRANCH, SHORT):
  4083.       know (issword (disp));
  4084.       fragP->fr_opcode[1] = 0x00;
  4085.       ext = 2;
  4086.       break;
  4087.     case TAB (ABRANCH, LONG):
  4088.       if (cpu_of_arch (current_architecture) < m68020)
  4089.     {
  4090.       if (fragP->fr_opcode[0] == 0x61)
  4091.         {
  4092.           fragP->fr_opcode[0] = 0x4E;
  4093.           fragP->fr_opcode[1] = 0xB9;    /* JBSR with ABSL LONG offset */
  4094.           subseg_change (text_section, 0); /* @@ */
  4095.  
  4096.           fix_new (fragP,
  4097.                fragP->fr_fix,
  4098.                4,
  4099.                fragP->fr_symbol,
  4100.                0,
  4101.                fragP->fr_offset,
  4102.                0,
  4103.                NO_RELOC);
  4104.  
  4105.           fragP->fr_fix += 4;
  4106.           ext = 0;
  4107.         }
  4108.       else if (fragP->fr_opcode[0] == 0x60)
  4109.         {
  4110.           fragP->fr_opcode[0] = 0x4E;
  4111.           fragP->fr_opcode[1] = 0xF9;    /* JMP  with ABSL LONG offset */
  4112.           subseg_change (text_section, 0); /* @@ */
  4113.           fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol, 0, fragP->fr_offset, 0,
  4114.                NO_RELOC);
  4115.           fragP->fr_fix += 4;
  4116.           ext = 0;
  4117.         }
  4118.       else
  4119.         {
  4120.           as_bad ("Long branch offset not supported.");
  4121.         }
  4122.     }
  4123.       else
  4124.     {
  4125.       fragP->fr_opcode[1] = 0xff;
  4126.       ext = 4;
  4127.     }
  4128.       break;
  4129.     case TAB (BCC68000, LONG):
  4130.       /* only Bcc 68000 instructions can come here */
  4131.       /* change bcc into b!cc/jmp absl long */
  4132.       fragP->fr_opcode[0] ^= 0x01;    /* invert bcc */
  4133.       fragP->fr_opcode[1] = 0x6;/* branch offset = 6 */
  4134.  
  4135.       /* JF: these used to be fr_opcode[2,3], but they may be in a
  4136.        different frag, in which case refering to them is a no-no.
  4137.        Only fr_opcode[0,1] are guaranteed to work. */
  4138.       *buffer_address++ = 0x4e;    /* put in jmp long (0x4ef9) */
  4139.       *buffer_address++ = 0xf9;
  4140.       fragP->fr_fix += 2;    /* account for jmp instruction */
  4141.       subseg_change (text_section, 0);
  4142.       fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol, 0,
  4143.            fragP->fr_offset, 0,
  4144.            NO_RELOC);
  4145.       fragP->fr_fix += 4;
  4146.       ext = 0;
  4147.       break;
  4148.     case TAB (DBCC, LONG):
  4149.       /* only DBcc 68000 instructions can come here */
  4150.       /* change dbcc into dbcc/jmp absl long */
  4151.       /* JF: these used to be fr_opcode[2-7], but that's wrong */
  4152.       *buffer_address++ = 0x00;    /* branch offset = 4 */
  4153.       *buffer_address++ = 0x04;
  4154.       *buffer_address++ = 0x60;    /* put in bra pc+6 */
  4155.       *buffer_address++ = 0x06;
  4156.       *buffer_address++ = 0x4e;    /* put in jmp long (0x4ef9) */
  4157.       *buffer_address++ = 0xf9;
  4158.  
  4159.       fragP->fr_fix += 6;    /* account for bra/jmp instructions */
  4160.       subseg_change (text_section, 0);
  4161.       fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol, 0,
  4162.            fragP->fr_offset, 0, NO_RELOC);
  4163.       fragP->fr_fix += 4;
  4164.       ext = 0;
  4165.       break;
  4166.     case TAB (FBRANCH, SHORT):
  4167.       know ((fragP->fr_opcode[1] & 0x40) == 0);
  4168.       ext = 2;
  4169.       break;
  4170.     case TAB (FBRANCH, LONG):
  4171.       fragP->fr_opcode[1] |= 0x40;    /* Turn on LONG bit */
  4172.       ext = 4;
  4173.       break;
  4174.     case TAB (PCREL, SHORT):
  4175.       ext = 2;
  4176.       break;
  4177.     case TAB (PCREL, LONG):
  4178.       /* The thing to do here is force it to ABSOLUTE LONG, since
  4179.     PCREL is really trying to shorten an ABSOLUTE address anyway */
  4180.       /* JF FOO This code has not been tested */
  4181.       subseg_change (text_section, 0);
  4182.       fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol, 0, fragP->fr_offset,
  4183.            0, NO_RELOC);
  4184.       if ((fragP->fr_opcode[1] & 0x3F) != 0x3A)
  4185.     as_bad ("Internal error (long PC-relative operand) for insn 0x%04lx at 0x%lx",
  4186.         fragP->fr_opcode[0], fragP->fr_address);
  4187.       fragP->fr_opcode[1] &= ~0x3F;
  4188.       fragP->fr_opcode[1] |= 0x39;    /* Mode 7.1 */
  4189.       fragP->fr_fix += 4;
  4190.       ext = 0;
  4191.       break;
  4192.     case TAB (PCLEA, SHORT):
  4193.       subseg_change (text_section, 0);
  4194.       fix_new (fragP, (int) (fragP->fr_fix), 2, fragP->fr_symbol,
  4195.            (symbolS *) 0, fragP->fr_offset, 1, NO_RELOC);
  4196.       fragP->fr_opcode[1] &= ~0x3F;
  4197.       fragP->fr_opcode[1] |= 0x3A;
  4198.       ext = 2;
  4199.       break;
  4200.     case TAB (PCLEA, LONG):
  4201.       subseg_change (text_section, 0);
  4202.       fix_new (fragP, (int) (fragP->fr_fix) + 2, 4, fragP->fr_symbol,
  4203.            (symbolS *) 0, fragP->fr_offset + 2, 1, NO_RELOC);
  4204.       *buffer_address++ = 0x01;
  4205.       *buffer_address++ = 0x70;
  4206.       fragP->fr_fix += 2;
  4207.       ext = 4;
  4208.       break;
  4209.     }
  4210.  
  4211.   if (ext)
  4212.     {
  4213.       md_number_to_chars (buffer_address, (long) disp, (int) ext);
  4214.       fragP->fr_fix += ext;
  4215.     }
  4216. }
  4217.  
  4218. #ifndef BFD_ASSEMBLER
  4219.  
  4220. void
  4221. md_convert_frag (headers, fragP)
  4222.      object_headers *headers;
  4223.      fragS *fragP;
  4224. {
  4225.   md_convert_frag_1 (fragP);
  4226. }
  4227.  
  4228. #else
  4229.  
  4230. void
  4231. md_convert_frag (abfd, sec, fragP)
  4232.      bfd *abfd;
  4233.      asection sec;
  4234.      fragS *fragP;
  4235. {
  4236.   md_convert_frag_1 (fragP);
  4237. }
  4238. #endif
  4239.  
  4240. /* Force truly undefined symbols to their maximum size, and generally set up
  4241.    the frag list to be relaxed
  4242.    */
  4243. int
  4244. md_estimate_size_before_relax (fragP, segment)
  4245.      register fragS *fragP;
  4246.      segT segment;
  4247. {
  4248.   int old_fix;
  4249.   register char *buffer_address = fragP->fr_fix + fragP->fr_literal;
  4250.  
  4251.   old_fix = fragP->fr_fix;
  4252.  
  4253.   /* handle SZ_UNDEF first, it can be changed to BYTE or SHORT */
  4254.   switch (fragP->fr_subtype)
  4255.     {
  4256.  
  4257.     case TAB (ABRANCH, SZ_UNDEF):
  4258.       {
  4259.     if ((fragP->fr_symbol != NULL)    /* Not absolute */
  4260.         && S_GET_SEGMENT (fragP->fr_symbol) == segment)
  4261.       {
  4262.         fragP->fr_subtype = TAB (TABTYPE (fragP->fr_subtype), BYTE);
  4263.         break;
  4264.       }
  4265.     else if ((fragP->fr_symbol == 0) || (cpu_of_arch (current_architecture) < m68020))
  4266.       {
  4267.         /* On 68000, or for absolute value, switch to abs long */
  4268.         /* FIXME, we should check abs val, pick short or long */
  4269.         if (fragP->fr_opcode[0] == 0x61)
  4270.           {
  4271.         fragP->fr_opcode[0] = 0x4E;
  4272.         fragP->fr_opcode[1] = 0xB9;    /* JBSR with ABSL LONG offset */
  4273.         subseg_change (text_section, 0);
  4274.         fix_new (fragP, fragP->fr_fix, 4,
  4275.              fragP->fr_symbol, 0, fragP->fr_offset, 0, NO_RELOC);
  4276.         fragP->fr_fix += 4;
  4277.         frag_wane (fragP);
  4278.           }
  4279.         else if (fragP->fr_opcode[0] == 0x60)
  4280.           {
  4281.         fragP->fr_opcode[0] = 0x4E;
  4282.         fragP->fr_opcode[1] = 0xF9;    /* JMP  with ABSL LONG offset */
  4283.         subseg_change (text_section, 0);
  4284.         fix_new (fragP, fragP->fr_fix, 4,
  4285.              fragP->fr_symbol, 0, fragP->fr_offset, 0, NO_RELOC);
  4286.         fragP->fr_fix += 4;
  4287.         frag_wane (fragP);
  4288.           }
  4289.         else
  4290.           {
  4291.         as_warn ("Long branch offset to extern symbol not supported.");
  4292.           }
  4293.       }
  4294.     else
  4295.       {            /* Symbol is still undefined.  Make it simple */
  4296.         fix_new (fragP, (int) (fragP->fr_fix), 4, fragP->fr_symbol,
  4297.              (symbolS *) 0, fragP->fr_offset + 4, 1, NO_RELOC);
  4298.         fragP->fr_fix += 4;
  4299.         fragP->fr_opcode[1] = 0xff;
  4300.         frag_wane (fragP);
  4301.         break;
  4302.       }
  4303.  
  4304.     break;
  4305.       }                /* case TAB(ABRANCH,SZ_UNDEF) */
  4306.  
  4307.     case TAB (FBRANCH, SZ_UNDEF):
  4308.       {
  4309.     if (S_GET_SEGMENT (fragP->fr_symbol) == segment || flagseen['l'])
  4310.       {
  4311.         fragP->fr_subtype = TAB (FBRANCH, SHORT);
  4312.         fragP->fr_var += 2;
  4313.       }
  4314.     else
  4315.       {
  4316.         fragP->fr_subtype = TAB (FBRANCH, LONG);
  4317.         fragP->fr_var += 4;
  4318.       }
  4319.     break;
  4320.       }                /* TAB(FBRANCH,SZ_UNDEF) */
  4321.  
  4322.     case TAB (PCREL, SZ_UNDEF):
  4323.       {
  4324.     if (S_GET_SEGMENT (fragP->fr_symbol) == segment || flagseen['l'])
  4325.       {
  4326.         fragP->fr_subtype = TAB (PCREL, SHORT);
  4327.         fragP->fr_var += 2;
  4328.       }
  4329.     else
  4330.       {
  4331.         fragP->fr_subtype = TAB (PCREL, LONG);
  4332.         fragP->fr_var += 4;
  4333.       }
  4334.     break;
  4335.       }                /* TAB(PCREL,SZ_UNDEF) */
  4336.  
  4337.     case TAB (BCC68000, SZ_UNDEF):
  4338.       {
  4339.     if ((fragP->fr_symbol != NULL)
  4340.         && S_GET_SEGMENT (fragP->fr_symbol) == segment)
  4341.       {
  4342.         fragP->fr_subtype = TAB (BCC68000, BYTE);
  4343.         break;
  4344.       }
  4345.     /* only Bcc 68000 instructions can come here */
  4346.     /* change bcc into b!cc/jmp absl long */
  4347.     fragP->fr_opcode[0] ^= 0x01;    /* invert bcc */
  4348.     if (flagseen['l'])
  4349.       {
  4350.         fragP->fr_opcode[1] = 0x04;    /* branch offset = 6 */
  4351.         /* JF: these were fr_opcode[2,3] */
  4352.         buffer_address[0] = 0x4e;    /* put in jmp long (0x4ef9) */
  4353.         buffer_address[1] = 0xf8;
  4354.         fragP->fr_fix += 2;    /* account for jmp instruction */
  4355.         subseg_change (text_section, 0);
  4356.         fix_new (fragP, fragP->fr_fix, 2, fragP->fr_symbol, 0,
  4357.              fragP->fr_offset, 0, NO_RELOC);
  4358.         fragP->fr_fix += 2;
  4359.       }
  4360.     else
  4361.       {
  4362.         fragP->fr_opcode[1] = 0x06;    /* branch offset = 6 */
  4363.         /* JF: these were fr_opcode[2,3] */
  4364.         buffer_address[0] = 0x4e;    /* put in jmp long (0x4ef9) */
  4365.         buffer_address[1] = 0xf9;
  4366.         fragP->fr_fix += 2;    /* account for jmp instruction */
  4367.         subseg_change (text_section, 0);
  4368.         fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol, 0,
  4369.              fragP->fr_offset, 0, NO_RELOC);
  4370.         fragP->fr_fix += 4;
  4371.       }
  4372.     frag_wane (fragP);
  4373.     break;
  4374.       }                /* case TAB(BCC68000,SZ_UNDEF) */
  4375.  
  4376.     case TAB (DBCC, SZ_UNDEF):
  4377.       {
  4378.     if (fragP->fr_symbol != NULL && S_GET_SEGMENT (fragP->fr_symbol) == segment)
  4379.       {
  4380.         fragP->fr_subtype = TAB (DBCC, SHORT);
  4381.         fragP->fr_var += 2;
  4382.         break;
  4383.       }
  4384.     /* only DBcc 68000 instructions can come here */
  4385.     /* change dbcc into dbcc/jmp absl long */
  4386.     /* JF: these used to be fr_opcode[2-4], which is wrong. */
  4387.     buffer_address[0] = 0x00;    /* branch offset = 4 */
  4388.     buffer_address[1] = 0x04;
  4389.     buffer_address[2] = 0x60;    /* put in bra pc + ... */
  4390.  
  4391.     if (flagseen['l'])
  4392.       {
  4393.         /* JF: these were fr_opcode[5-7] */
  4394.         buffer_address[3] = 0x04;    /* plus 4 */
  4395.         buffer_address[4] = 0x4e;    /* Put in Jump Word */
  4396.         buffer_address[5] = 0xf8;
  4397.         fragP->fr_fix += 6;    /* account for bra/jmp instruction */
  4398.         subseg_change (text_section, 0);
  4399.         fix_new (fragP, fragP->fr_fix, 2, fragP->fr_symbol, 0,
  4400.  
  4401.  
  4402.              fragP->fr_offset, 0, NO_RELOC);
  4403.         fragP->fr_fix += 2;
  4404.       }
  4405.     else
  4406.       {
  4407.         /* JF: these were fr_opcode[5-7] */
  4408.         buffer_address[3] = 0x06;    /* Plus 6 */
  4409.         buffer_address[4] = 0x4e;    /* put in jmp long (0x4ef9) */
  4410.         buffer_address[5] = 0xf9;
  4411.         fragP->fr_fix += 6;    /* account for bra/jmp instruction */
  4412.         subseg_change (text_section, 0);
  4413.         fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol, 0,
  4414.              fragP->fr_offset, 0, NO_RELOC);
  4415.         fragP->fr_fix += 4;
  4416.       }
  4417.  
  4418.     frag_wane (fragP);
  4419.     break;
  4420.       }                /* case TAB(DBCC,SZ_UNDEF) */
  4421.  
  4422.     case TAB (PCLEA, SZ_UNDEF):
  4423.       {
  4424.     if ((S_GET_SEGMENT (fragP->fr_symbol)) == segment || flagseen['l'])
  4425.       {
  4426.         fragP->fr_subtype = TAB (PCLEA, SHORT);
  4427.         fragP->fr_var += 2;
  4428.       }
  4429.     else
  4430.       {
  4431.         fragP->fr_subtype = TAB (PCLEA, LONG);
  4432.         fragP->fr_var += 6;
  4433.       }
  4434.     break;
  4435.       }                /* TAB(PCLEA,SZ_UNDEF) */
  4436.  
  4437.     default:
  4438.       break;
  4439.  
  4440.     }                /* switch on subtype looking for SZ_UNDEF's. */
  4441.  
  4442.   /* now that SZ_UNDEF are taken care of, check others */
  4443.   switch (fragP->fr_subtype)
  4444.     {
  4445.     case TAB (BCC68000, BYTE):
  4446.     case TAB (ABRANCH, BYTE):
  4447.       /* We can't do a short jump to the next instruction,
  4448.        so we force word mode.  */
  4449.       if (fragP->fr_symbol && S_GET_VALUE (fragP->fr_symbol) == 0 &&
  4450.       fragP->fr_symbol->sy_frag == fragP->fr_next)
  4451.     {
  4452.       fragP->fr_subtype = TAB (TABTYPE (fragP->fr_subtype), SHORT);
  4453.       fragP->fr_var += 2;
  4454.     }
  4455.       break;
  4456.     default:
  4457.       break;
  4458.     }
  4459.   return fragP->fr_var + fragP->fr_fix - old_fix;
  4460. }
  4461.  
  4462. #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
  4463. /* the bit-field entries in the relocation_info struct plays hell
  4464.    with the byte-order problems of cross-assembly.  So as a hack,
  4465.    I added this mach. dependent ri twiddler.  Ugly, but it gets
  4466.    you there. -KWK */
  4467. /* on m68k: first 4 bytes are normal unsigned long, next three bytes
  4468.    are symbolnum, most sig. byte first.  Last byte is broken up with
  4469.    bit 7 as pcrel, bits 6 & 5 as length, bit 4 as pcrel, and the lower
  4470.    nibble as nuthin. (on Sun 3 at least) */
  4471. /* Translate the internal relocation information into target-specific
  4472.    format. */
  4473. #ifdef comment
  4474. void
  4475. md_ri_to_chars (the_bytes, ri)
  4476.      char *the_bytes;
  4477.      struct reloc_info_generic *ri;
  4478. {
  4479.   /* this is easy */
  4480.   md_number_to_chars (the_bytes, ri->r_address, 4);
  4481.   /* now the fun stuff */
  4482.   the_bytes[4] = (ri->r_symbolnum >> 16) & 0x0ff;
  4483.   the_bytes[5] = (ri->r_symbolnum >> 8) & 0x0ff;
  4484.   the_bytes[6] = ri->r_symbolnum & 0x0ff;
  4485.   the_bytes[7] = (((ri->r_pcrel << 7) & 0x80) | ((ri->r_length << 5) & 0x60) |
  4486.           ((ri->r_extern << 4) & 0x10));
  4487. }
  4488.  
  4489. #endif /* comment */
  4490.  
  4491. #ifndef BFD_ASSEMBLER
  4492. void
  4493. tc_aout_fix_to_chars (where, fixP, segment_address_in_file)
  4494.      char *where;
  4495.      fixS *fixP;
  4496.      relax_addressT segment_address_in_file;
  4497. {
  4498.   /*
  4499.    * In: length of relocation (or of address) in chars: 1, 2 or 4.
  4500.    * Out: GNU LD relocation length code: 0, 1, or 2.
  4501.    */
  4502.  
  4503.   static CONST unsigned char nbytes_r_length[] =
  4504.   {42, 0, 1, 42, 2};
  4505.   long r_symbolnum;
  4506.  
  4507.   know (fixP->fx_addsy != NULL);
  4508.  
  4509.   md_number_to_chars (where,
  4510.        fixP->fx_frag->fr_address + fixP->fx_where - segment_address_in_file,
  4511.               4);
  4512.  
  4513.   r_symbolnum = (S_IS_DEFINED (fixP->fx_addsy)
  4514.          ? S_GET_TYPE (fixP->fx_addsy)
  4515.          : fixP->fx_addsy->sy_number);
  4516.  
  4517.   where[4] = (r_symbolnum >> 16) & 0x0ff;
  4518.   where[5] = (r_symbolnum >> 8) & 0x0ff;
  4519.   where[6] = r_symbolnum & 0x0ff;
  4520.   where[7] = (((fixP->fx_pcrel << 7) & 0x80) | ((nbytes_r_length[fixP->fx_size] << 5) & 0x60) |
  4521.           (((!S_IS_DEFINED (fixP->fx_addsy)) << 4) & 0x10));
  4522.  
  4523.   return;
  4524. }
  4525. #endif
  4526.  
  4527. #endif /* OBJ_AOUT or OBJ_BOUT */
  4528.  
  4529. #ifndef WORKING_DOT_WORD
  4530. CONST int md_short_jump_size = 4;
  4531. CONST int md_long_jump_size = 6;
  4532.  
  4533. void
  4534. md_create_short_jump (ptr, from_addr, to_addr, frag, to_symbol)
  4535.      char *ptr;
  4536.      long from_addr, to_addr;
  4537.      fragS *frag;
  4538.      symbolS *to_symbol;
  4539. {
  4540.   long offset;
  4541.  
  4542.   offset = to_addr - (from_addr + 2);
  4543.  
  4544.   md_number_to_chars (ptr, (long) 0x6000, 2);
  4545.   md_number_to_chars (ptr + 2, (long) offset, 2);
  4546. }
  4547.  
  4548. void
  4549. md_create_long_jump (ptr, from_addr, to_addr, frag, to_symbol)
  4550.      char *ptr;
  4551.      long from_addr, to_addr;
  4552.      fragS *frag;
  4553.      symbolS *to_symbol;
  4554. {
  4555.   long offset;
  4556.  
  4557.   if (cpu_of_arch (current_architecture) < m68020)
  4558.     {
  4559.       offset = to_addr - S_GET_VALUE (to_symbol);
  4560.       md_number_to_chars (ptr, (long) 0x4EF9, 2);
  4561.       md_number_to_chars (ptr + 2, (long) offset, 4);
  4562.       fix_new (frag, (ptr + 2) - frag->fr_literal, 4, to_symbol, (symbolS *) 0, (long) 0, 0,
  4563.            NO_RELOC);
  4564.     }
  4565.   else
  4566.     {
  4567.       offset = to_addr - (from_addr + 2);
  4568.       md_number_to_chars (ptr, (long) 0x60ff, 2);
  4569.       md_number_to_chars (ptr + 2, (long) offset, 4);
  4570.     }
  4571. }
  4572.  
  4573. #endif
  4574. /* Different values of OK tell what its OK to return.  Things that aren't OK are an error (what a shock, no?)
  4575.  
  4576.    0:  Everything is OK
  4577.    10:  Absolute 1:8    only
  4578.    20:  Absolute 0:7    only
  4579.    30:  absolute 0:15    only
  4580.    40:  Absolute 0:31    only
  4581.    50:  absolute 0:127    only
  4582.    55:  absolute -64:63    only
  4583.    60:  absolute -128:127    only
  4584.    70:  absolute 0:4095    only
  4585.    80:  No bignums
  4586.  
  4587.    */
  4588.  
  4589. static int
  4590. get_num (exp, ok)
  4591.      struct m68k_exp *exp;
  4592.      int ok;
  4593. {
  4594. #ifdef TEST2
  4595.   long l = 0;
  4596.  
  4597.   if (!exp->e_beg)
  4598.     return 0;
  4599.   if (*exp->e_beg == '0')
  4600.     {
  4601.       if (exp->e_beg[1] == 'x')
  4602.     sscanf (exp->e_beg + 2, "%x", &l);
  4603.       else
  4604.     sscanf (exp->e_beg + 1, "%O", &l);
  4605.       return l;
  4606.     }
  4607.   return atol (exp->e_beg);
  4608. #else
  4609.   char *save_in;
  4610.   char c_save;
  4611.   segT section;
  4612.  
  4613.   if (!exp)
  4614.     {
  4615.       /* Can't do anything */
  4616.       return 0;
  4617.     }
  4618.   if (!exp->e_beg || !exp->e_end)
  4619.     {
  4620.       seg (exp) = absolute_section;
  4621.       adds (exp) = 0;
  4622.       subs (exp) = 0;
  4623.       offs (exp) = (ok == 10) ? 1 : 0;
  4624.       as_warn ("Null expression defaults to %ld", offs (exp));
  4625.       return 0;
  4626.     }
  4627.  
  4628.   exp->e_siz = 0;
  4629.   if ( /* ok!=80 && */ (exp->e_end[-1] == ':' || exp->e_end[-1] == '.')
  4630.       && (exp->e_end - exp->e_beg) >= 2)
  4631.     {
  4632.       switch (exp->e_end[0])
  4633.     {
  4634.     case 's':
  4635.     case 'S':
  4636.     case 'b':
  4637.     case 'B':
  4638.       exp->e_siz = 1;
  4639.       exp->e_end -= 2;
  4640.       break;
  4641.     case 'w':
  4642.     case 'W':
  4643.       exp->e_siz = 2;
  4644.       exp->e_end -= 2;
  4645.       break;
  4646.     case 'l':
  4647.     case 'L':
  4648.       exp->e_siz = 3;
  4649.       exp->e_end -= 2;
  4650.       break;
  4651.     default:
  4652.       if (exp->e_end[-1] == ':')
  4653.         as_bad ("Unknown size for expression \"%c\"", exp->e_end[0]);
  4654.       break;
  4655.     }
  4656.     }
  4657.   c_save = exp->e_end[1];
  4658.   exp->e_end[1] = '\0';
  4659.   save_in = input_line_pointer;
  4660.   input_line_pointer = exp->e_beg;
  4661.   section = expression (&exp->e_exp);
  4662.   if (section == pass1_section)
  4663.     {
  4664.       seg (exp) = absolute_section;
  4665.       adds (exp) = 0;
  4666.       subs (exp) = 0;
  4667.       offs (exp) = (ok == 10) ? 1 : 0;
  4668.       as_warn ("Unknown expression: '%s' defaulting to %d", exp->e_beg, offs (exp));
  4669.     }
  4670.   else if (section == absent_section)
  4671.     {
  4672.       /* Do the same thing the VAX asm does */
  4673.       seg (exp) = absolute_section;
  4674.       adds (exp) = 0;
  4675.       subs (exp) = 0;
  4676.       offs (exp) = 0;
  4677.       if (ok == 10)
  4678.     {
  4679.       as_warn ("expression out of range: defaulting to 1");
  4680.       offs (exp) = 1;
  4681.     }
  4682.     }
  4683.   else if (section == absolute_section)
  4684.     {
  4685.       switch (ok)
  4686.     {
  4687.     case 10:
  4688.       if (offs (exp) < 1 || offs (exp) > 8)
  4689.         {
  4690.           as_warn ("expression out of range: defaulting to 1");
  4691.           offs (exp) = 1;
  4692.         }
  4693.       break;
  4694.     case 20:
  4695.       if (offs (exp) < 0 || offs (exp) > 7)
  4696.         goto outrange;
  4697.       break;
  4698.     case 30:
  4699.       if (offs (exp) < 0 || offs (exp) > 15)
  4700.         goto outrange;
  4701.       break;
  4702.     case 40:
  4703.       if (offs (exp) < 0 || offs (exp) > 32)
  4704.         goto outrange;
  4705.       break;
  4706.     case 50:
  4707.       if (offs (exp) < 0 || offs (exp) > 127)
  4708.         goto outrange;
  4709.       break;
  4710.     case 55:
  4711.       if (offs (exp) < -64 || offs (exp) > 63)
  4712.         goto outrange;
  4713.       break;
  4714.     case 60:
  4715.       if (offs (exp) < -128 || offs (exp) > 127)
  4716.         goto outrange;
  4717.       break;
  4718.     case 70:
  4719.       if (offs (exp) < 0 || offs (exp) > 4095)
  4720.         {
  4721.         outrange:
  4722.           as_warn ("expression out of range: defaulting to 0");
  4723.           offs (exp) = 0;
  4724.         }
  4725.       break;
  4726.     default:
  4727.       break;
  4728.     }
  4729.     }
  4730.   else if (section == big_section)
  4731.     {
  4732.       if (offs (exp) < 0    /* flonum */
  4733.       && (ok == 80        /* no bignums */
  4734.           || (ok > 10    /* small-int ranges including 0 ok */
  4735.           /* If we have a flonum zero, a zero integer should
  4736.              do as well (e.g., in moveq).  */
  4737.           && generic_floating_point_number.exponent == 0
  4738.           && generic_floating_point_number.low[0] == 0)))
  4739.     {
  4740.       /* HACK! Turn it into a long */
  4741.       LITTLENUM_TYPE words[6];
  4742.  
  4743.       gen_to_words (words, 2, 8L);    /* These numbers are magic! */
  4744.       seg (exp) = absolute_section;
  4745.       adds (exp) = 0;
  4746.       subs (exp) = 0;
  4747.       offs (exp) = words[1] | (words[0] << 16);
  4748.     }
  4749.       else if (ok != 0)
  4750.     {
  4751.       seg (exp) = absolute_section;
  4752.       adds (exp) = 0;
  4753.       subs (exp) = 0;
  4754.       offs (exp) = (ok == 10) ? 1 : 0;
  4755.       as_warn ("Can't deal with expression \"%s\": defaulting to %ld", exp->e_beg, offs (exp));
  4756.     }
  4757.     }
  4758.   else
  4759.     {
  4760.       if (ok >= 10 && ok <= 70)
  4761.     {
  4762.       seg (exp) = absolute_section;
  4763.       adds (exp) = 0;
  4764.       subs (exp) = 0;
  4765.       offs (exp) = (ok == 10) ? 1 : 0;
  4766.       as_warn ("Can't deal with expression \"%s\": defaulting to %ld", exp->e_beg, offs (exp));
  4767.     }
  4768.     }
  4769.  
  4770.   if (input_line_pointer != exp->e_end + 1)
  4771.     as_bad ("Ignoring junk after expression");
  4772.   exp->e_end[1] = c_save;
  4773.   input_line_pointer = save_in;
  4774.   if (exp->e_siz)
  4775.     {
  4776.       switch (exp->e_siz)
  4777.     {
  4778.     case 1:
  4779.       if (!isbyte (offs (exp)))
  4780.         as_warn ("expression doesn't fit in BYTE");
  4781.       break;
  4782.     case 2:
  4783.       if (!isword (offs (exp)))
  4784.         as_warn ("expression doesn't fit in WORD");
  4785.       break;
  4786.     }
  4787.     }
  4788.   return offs (exp);
  4789. #endif
  4790. }
  4791.  
  4792. /* These are the back-ends for the various machine dependent pseudo-ops.  */
  4793. void demand_empty_rest_of_line ();    /* Hate those extra verbose names */
  4794.  
  4795. static void
  4796. s_data1 ()
  4797. {
  4798.   subseg_new (data_section, 1);
  4799.   demand_empty_rest_of_line ();
  4800. }
  4801.  
  4802. static void
  4803. s_data2 ()
  4804. {
  4805.   subseg_new (data_section, 2);
  4806.   demand_empty_rest_of_line ();
  4807. }
  4808.  
  4809. static void
  4810. s_bss ()
  4811. {
  4812.   /* We don't support putting frags in the BSS segment, we fake it
  4813.      by marking in_bss, then looking at s_skip for clues.  */
  4814.  
  4815.   subseg_new (bss_section, 0);
  4816.   demand_empty_rest_of_line ();
  4817. }
  4818.  
  4819. static void
  4820. s_even ()
  4821. {
  4822.   register int temp;
  4823.   register long temp_fill;
  4824.  
  4825.   temp = 1;            /* JF should be 2? */
  4826.   temp_fill = get_absolute_expression ();
  4827.   if (!need_pass_2)        /* Never make frag if expect extra pass. */
  4828.     frag_align (temp, (int) temp_fill);
  4829.   demand_empty_rest_of_line ();
  4830. }
  4831.  
  4832. static void
  4833. s_proc ()
  4834. {
  4835.   demand_empty_rest_of_line ();
  4836. }
  4837.  
  4838. /* s_space is defined in read.c .skip is simply an alias to it. */
  4839.  
  4840. /*
  4841.  * md_parse_option
  4842.  *    Invocation line includes a switch not recognized by the base assembler.
  4843.  *    See if it's a processor-specific option.  These are:
  4844.  *
  4845.  *    -[A]m[c]68000, -[A]m[c]68008, -[A]m[c]68010, -[A]m[c]68020, -[A]m[c]68030, -[A]m[c]68040
  4846.  *    -[A]m[c]68881, -[A]m[c]68882, -[A]m[c]68851
  4847.  *        Select the architecture.  Instructions or features not
  4848.  *        supported by the selected architecture cause fatal
  4849.  *        errors.  More than one may be specified.  The default is
  4850.  *        -m68020 -m68851 -m68881.  Note that -m68008 is a synonym
  4851.  *        for -m68000, and -m68882 is a synonym for -m68881.
  4852.  *    -[A]m[c]no-68851, -[A]m[c]no-68881
  4853.  *        Don't accept 688?1 instructions.  (The "c" is kind of silly,
  4854.  *        so don't use or document it, but that's the way the parsing
  4855.  *        works).
  4856.  *
  4857.  * MAYBE_FLOAT_TOO is defined below so that specifying a processor type
  4858.  * (e.g. m68020) also requests that float instructions be included.  This
  4859.  * is the default setup, mostly to avoid hassling users.  A better
  4860.  * rearrangement of this structure would be to add an option to DENY
  4861.  * floating point opcodes, for people who want to really know there's none
  4862.  * of that funny floaty stuff going on.  FIXME-later.
  4863.  */
  4864. #ifndef MAYBE_FLOAT_TOO
  4865. #define    MAYBE_FLOAT_TOO    /* m68881 */ 0    /* this is handled later */
  4866. #endif
  4867.  
  4868. int
  4869. md_parse_option (argP, cntP, vecP)
  4870.      char **argP;
  4871.      int *cntP;
  4872.      char ***vecP;
  4873. {
  4874.   switch (**argP)
  4875.     {
  4876.     case 'l':            /* -l means keep external to 2 bit offset
  4877.                    rather than 16 bit one */
  4878.       break;
  4879.  
  4880.     case 'S':            /* -S means that jbsr's always turn into
  4881.                    jsr's.  */
  4882.       break;
  4883.  
  4884.     case 'A':
  4885.       (*argP)++;
  4886.       /* intentional fall-through */
  4887.     case 'm':
  4888.       (*argP)++;
  4889.  
  4890.       if (**argP == 'c')
  4891.     {
  4892.       (*argP)++;
  4893.     }            /* allow an optional "c" */
  4894.  
  4895.       if (!strcmp (*argP, "68000")
  4896.       || !strcmp (*argP, "68008")
  4897.       || !strcmp (*argP, "68302"))
  4898.     {
  4899.       current_architecture |= m68000;
  4900.     }
  4901.       else if (!strcmp (*argP, "68010"))
  4902.     {
  4903. #ifdef TE_SUN
  4904.       omagic = 1 << 16 | OMAGIC;
  4905. #endif
  4906.       current_architecture |= m68010;
  4907.     }
  4908.       else if (!strcmp (*argP, "68020"))
  4909.     {
  4910.       current_architecture |= m68020 | MAYBE_FLOAT_TOO;
  4911.     }
  4912.       else if (!strcmp (*argP, "68030"))
  4913.     {
  4914.       current_architecture |= m68030 | MAYBE_FLOAT_TOO;
  4915.     }
  4916.       else if (!strcmp (*argP, "68040"))
  4917.     {
  4918.       current_architecture |= m68040 | MAYBE_FLOAT_TOO;
  4919.     }
  4920. #ifndef NO_68881
  4921.       else if (!strcmp (*argP, "68881"))
  4922.     {
  4923.       current_architecture |= m68881;
  4924.     }
  4925.       else if (!strcmp (*argP, "68882"))
  4926.     {
  4927.       current_architecture |= m68882;
  4928.     }
  4929. #endif /* NO_68881 */
  4930.       /* Even if we aren't configured to support the processor,
  4931.      it should still be possible to assert that the user
  4932.      doesn't have it...  */
  4933.       else if (!strcmp (*argP, "no-68881")
  4934.            || !strcmp (*argP, "no-68882"))
  4935.     {
  4936.       no_68881 = 1;
  4937.     }
  4938. #ifndef NO_68851
  4939.       else if (!strcmp (*argP, "68851"))
  4940.     {
  4941.       current_architecture |= m68851;
  4942.     }
  4943. #endif /* NO_68851 */
  4944.       else if (!strcmp (*argP, "no-68851"))
  4945.     {
  4946.       no_68851 = 1;
  4947.     }
  4948.       else if (!strcmp (*argP, "pu32") /* "cpu32" minus 'c' */
  4949.            || !strcmp (*argP, "68331")
  4950.            || !strcmp (*argP, "68332")
  4951.            || !strcmp (*argP, "68333")
  4952.            || !strcmp (*argP, "68340"))
  4953.     {
  4954.       current_architecture |= cpu32;
  4955.     }
  4956.       else
  4957.     {
  4958.       as_warn ("Unknown architecture, \"%s\". option ignored", *argP);
  4959.     }            /* switch on architecture */
  4960.  
  4961.       while (**argP)
  4962.     (*argP)++;
  4963.  
  4964.       break;
  4965.  
  4966.     case 'p':
  4967.       if (!strcmp (*argP, "pic"))
  4968.     {
  4969.       (*argP) += 3;
  4970.       break;        /* -pic, Position Independent Code */
  4971.     }
  4972.       else
  4973.     {
  4974.       return 0;
  4975.     }            /* pic or not */
  4976.  
  4977.     default:
  4978.       return 0;
  4979.     }
  4980.   return 1;
  4981. }
  4982.  
  4983.  
  4984. #ifdef TEST2
  4985.  
  4986. /* TEST2:  Test md_assemble() */
  4987. /* Warning, this routine probably doesn't work anymore */
  4988.  
  4989. main ()
  4990. {
  4991.   struct m68k_it the_ins;
  4992.   char buf[120];
  4993.   char *cp;
  4994.   int n;
  4995.  
  4996.   m68k_ip_begin ();
  4997.   for (;;)
  4998.     {
  4999.       if (!gets (buf) || !*buf)
  5000.     break;
  5001.       if (buf[0] == '|' || buf[1] == '.')
  5002.     continue;
  5003.       for (cp = buf; *cp; cp++)
  5004.     if (*cp == '\t')
  5005.       *cp = ' ';
  5006.       if (is_label (buf))
  5007.     continue;
  5008.       memset (&the_ins, '\0', sizeof (the_ins));
  5009.       m68k_ip (&the_ins, buf);
  5010.       if (the_ins.error)
  5011.     {
  5012.       printf ("Error %s in %s\n", the_ins.error, buf);
  5013.     }
  5014.       else
  5015.     {
  5016.       printf ("Opcode(%d.%s): ", the_ins.numo, the_ins.args);
  5017.       for (n = 0; n < the_ins.numo; n++)
  5018.         printf (" 0x%x", the_ins.opcode[n] & 0xffff);
  5019.       printf ("    ");
  5020.       print_the_insn (&the_ins.opcode[0], stdout);
  5021.       (void) putchar ('\n');
  5022.     }
  5023.       for (n = 0; n < strlen (the_ins.args) / 2; n++)
  5024.     {
  5025.       if (the_ins.operands[n].error)
  5026.         {
  5027.           printf ("op%d Error %s in %s\n", n, the_ins.operands[n].error, buf);
  5028.           continue;
  5029.         }
  5030.       printf ("mode %d, reg %d, ", the_ins.operands[n].mode, the_ins.operands[n].reg);
  5031.       if (the_ins.operands[n].b_const)
  5032.         printf ("Constant: '%.*s', ", 1 + the_ins.operands[n].e_const - the_ins.operands[n].b_const, the_ins.operands[n].b_const);
  5033.       printf ("ireg %d, isiz %d, imul %d, ", the_ins.operands[n].ireg, the_ins.operands[n].isiz, the_ins.operands[n].imul);
  5034.       if (the_ins.operands[n].b_iadd)
  5035.         printf ("Iadd: '%.*s',", 1 + the_ins.operands[n].e_iadd - the_ins.operands[n].b_iadd, the_ins.operands[n].b_iadd);
  5036.       (void) putchar ('\n');
  5037.     }
  5038.     }
  5039.   m68k_ip_end ();
  5040.   return 0;
  5041. }
  5042.  
  5043. is_label (str)
  5044.      char *str;
  5045. {
  5046.   while (*str == ' ')
  5047.     str++;
  5048.   while (*str && *str != ' ')
  5049.     str++;
  5050.   if (str[-1] == ':' || str[1] == '=')
  5051.     return 1;
  5052.   return 0;
  5053. }
  5054.  
  5055. #endif
  5056.  
  5057. /* Possible states for relaxation:
  5058.  
  5059.    0 0    branch offset    byte    (bra, etc)
  5060.    0 1            word
  5061.    0 2            long
  5062.  
  5063.    1 0    indexed offsets    byte    a0@(32,d4:w:1) etc
  5064.    1 1            word
  5065.    1 2            long
  5066.  
  5067.    2 0    two-offset index word-word a0@(32,d4)@(45) etc
  5068.    2 1            word-long
  5069.    2 2            long-word
  5070.    2 3            long-long
  5071.  
  5072.    */
  5073.  
  5074. /* We have no need to default values of symbols.  */
  5075.  
  5076. /* ARGSUSED */
  5077. symbolS *
  5078. md_undefined_symbol (name)
  5079.      char *name;
  5080. {
  5081.   return 0;
  5082. }
  5083.  
  5084. /* Parse an operand that is machine-specific.
  5085.    We just return without modifying the expression if we have nothing
  5086.    to do.  */
  5087.  
  5088. /* ARGSUSED */
  5089. void
  5090. md_operand (expressionP)
  5091.      expressionS *expressionP;
  5092. {
  5093. }
  5094.  
  5095. /* Round up a section size to the appropriate boundary.  */
  5096. long
  5097. md_section_align (segment, size)
  5098.      segT segment;
  5099.      long size;
  5100. {
  5101.   return size;            /* Byte alignment is fine */
  5102. }
  5103.  
  5104. /* Exactly what point is a PC-relative offset relative TO?
  5105.    On the 68k, they're relative to the address of the offset, plus
  5106.    its size. (??? Is this right?  FIXME-SOON!) */
  5107. long
  5108. md_pcrel_from (fixP)
  5109.      fixS *fixP;
  5110. {
  5111.   return (fixP->fx_size + fixP->fx_where + fixP->fx_frag->fr_address);
  5112. }
  5113.  
  5114. #ifndef BFD_ASSEMBLER
  5115. void
  5116. tc_coff_symbol_emit_hook ()
  5117. {
  5118. }
  5119.  
  5120. int
  5121. tc_coff_sizemachdep (frag)
  5122.      fragS *frag;
  5123. {
  5124.   switch (frag->fr_subtype & 0x3)
  5125.     {
  5126.     case BYTE:
  5127.       return 1;
  5128.     case SHORT:
  5129.       return 2;
  5130.     case LONG:
  5131.       return 4;
  5132.     default:
  5133.       abort ();
  5134.     }
  5135. }
  5136. #endif
  5137.  
  5138. /* end of tc-m68k.c */
  5139.